Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datatable, command and parameter objects

Status
Not open for further replies.

smsinger3

Programmer
Oct 5, 2000
192
US
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 <> &quot;&quot; Then
Return (&quot;AddParam:&quot; & astrFldName & &quot;: &quot; & 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 (&quot;&quot;)



End Function
 
Well....after stepping through my code, I discovered that this works perfectly. All I wanted to do was retrieve an employee record based on his userid. Instead, I passed the domain/username, thus did not get any records in return. Stupid Stupid Stupid.....B-(

Have a nice day
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top