I am not able to return a recordset with a MSSQLServerPreparedStatement. However, I can return a recordset with the equivalent database SQLSelect.
This code works and returns a recordset.
If db.Connect Then
dim rs as RecordSet = db.SQLSelect("SELECT Cus_No, Cus_Name FROM ARCusFil_SQL where Cus_No = '000000000100' ")
If rs <> Nil Then
While Not rs.EOF
cusnostring = rs.IdxField(1).StringValue.Trim
rs.MoveNext
Wend
rs.Close
End If
Else
MsgBox("Connection error:" + db.ErrorMessage)
End If
This code does not work. The rs is Nil.
If db.Connect Then
Dim ps As MSSQLServerPreparedStatement
ps = db.Prepare("SELECT Cus_No, Cus_Name FROM ARCusFil_SQL Where Cus_No = ? ")
ps.Bind(0, "000000000100")
Dim rs As RecordSet = ps.SQLSelect
If rs <> Nil Then
While Not rs.EOF
cusnostring = rs.IdxField(1).StringValue.Trim
rs.MoveNext
Wend
rs.Close
End If
Else
MsgBox("Connection error:" + db.ErrorMessage)
End If
Can anyone offer some suggestions as to the problem with my prepared statement code?
Thanks,
pat
Dim ps As MSSQLServerPreparedStatement
ps = db.Prepare("SELECT Cus_No, Cus_Name FROM ARCusFil_SQL Where Cus_No = ? ")
ps.BindType(0, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
ps.Bind(0, "000000000100")
Norman,
Thank you. That was an error in my posting. The BindType statement is in my code. I just forgot to include it in my post.
I saw that document and I my code is essentially a copy of it.
This is my first exposure to Xojo and to the MSSQLServerPreparedStatement. I am sure it works and that I am just missing something elementary.
pat
Corrected code.
Dim ps As MSSQLServerPreparedStatement
ps = db.Prepare("SELECT Cus_No, Cus_Name FROM ARCusFil_SQL Where Cus_No = ? ")
ps.BindType(0, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
ps.Bind(0, "000000000100")
Dim rs As RecordSet = ps.SQLSelect
SQLSelect returns a Nil RecordSet from even the simplest query using MSSQLServerPreparedStatement. There are no MSSQLServerDatabase errors. This appears to be a bug that should get some attention and a fix.