Hello all. I am using paramaters on the command object to try to create a datatable. It seems to run ok, except it doesn't return any rows. It works correctly when I don't use paramters. I'm baffled. Can you see what I'm doing wrong?
Your help is certainly appreciated!
Steve
---code to call objDat to return a datatable-----------
dim dt as datatable
'objDat - a class I wrote to bring back data.
objDat.AddParam("LOGON_ID", OleDbType.Char, ParameterDirection.Input, 50, strIDToVerify)
strErrMsg = objDat.ExecuteCmd("select * from logontable where userid = ?", dt, 1)
strTmp = dt.Rows(0).item(0).ToString
At this point, dt should contain the datatable with at least 1 record, but it's empty. Why?
------taken from a class I created to return the datatable ----
Public Function AddParam(ByVal astrFldName As String, ByVal aintType As OleDbType, ByVal aintDir As ParameterDirection, ByVal aintSize As Integer, ByVal astrValue As String) As String
cd.Parameters.Add(New OleDbParameter(astrFldName, aintType, aintSize))
cd.Parameters(cd.Parameters.Count - 1).Direction = aintDir
cd.Parameters(cd.Parameters.Count - 1).Value = astrValue
If Err.Description <> "" Then
Return ("AddParam:" & astrFldName & ": " & Err.Description)
End If
End Function
Public Function ExecuteCmd(ByVal astrSQL As String, ByRef dt As DataTable, ByVal aintExpect As ReturnRows) As String
Dim cn As New OleDbConnection(cnString)
cn.Open()
'Set the connection. The command object is defined elsewhere.
cd.Connection = cn
cd.CommandText = astrSQL
cd.CommandType = System.Data.CommandType.Text
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
da.SelectCommand = cd
Dim dt As New DataTable()
da.Fill(dt)
Return (""
End Function
Your help is certainly appreciated!
Steve
---code to call objDat to return a datatable-----------
dim dt as datatable
'objDat - a class I wrote to bring back data.
objDat.AddParam("LOGON_ID", OleDbType.Char, ParameterDirection.Input, 50, strIDToVerify)
strErrMsg = objDat.ExecuteCmd("select * from logontable where userid = ?", dt, 1)
strTmp = dt.Rows(0).item(0).ToString
At this point, dt should contain the datatable with at least 1 record, but it's empty. Why?
------taken from a class I created to return the datatable ----
Public Function AddParam(ByVal astrFldName As String, ByVal aintType As OleDbType, ByVal aintDir As ParameterDirection, ByVal aintSize As Integer, ByVal astrValue As String) As String
cd.Parameters.Add(New OleDbParameter(astrFldName, aintType, aintSize))
cd.Parameters(cd.Parameters.Count - 1).Direction = aintDir
cd.Parameters(cd.Parameters.Count - 1).Value = astrValue
If Err.Description <> "" Then
Return ("AddParam:" & astrFldName & ": " & Err.Description)
End If
End Function
Public Function ExecuteCmd(ByVal astrSQL As String, ByRef dt As DataTable, ByVal aintExpect As ReturnRows) As String
Dim cn As New OleDbConnection(cnString)
cn.Open()
'Set the connection. The command object is defined elsewhere.
cd.Connection = cn
cd.CommandText = astrSQL
cd.CommandType = System.Data.CommandType.Text
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
da.SelectCommand = cd
Dim dt As New DataTable()
da.Fill(dt)
Return (""
End Function