Problem with SQL statement
Hi,
I need some help with a little SQl problem.
I'm using VB 2005 en SQL Express.
I have build a SQL statement like this:
SELECT * FROM USERS WHERE (ACHTERNAAM LIKE '%' + @PARAM_LASTNAME + '%')
I have created it through the query builder, if i run it there it works fine.
VB 2005 creates his own code, so you can call the procedure.
It looks like this:
Public Overloads Overridable Function FillByAchternaam(ByVal dataTable As CRMDATA.USERSDataTable, ByVal PARAM_LASTNAME As String) As Integer
Me.Adapter.SelectCommand = Me.CommandCollection(3)
If (PARAMACHTERNAAM Is Nothing) Then
Throw New System.ArgumentNullException("PARAM_LASTNAME")
Else
Me.Adapter.SelectCommand.Parameters(0).Value = CType(PARAMACHTERNAAM,String)
End If
If (Me.m_clearBeforeFill = true) Then
dataTable.Clear
End If
Dim returnValue As Integer = Me.Adapter.Fill(dataTable)
Return returnValue
End Function
I call it this way:
Me.USERSTableAdapter.FillByAchternaam(DataTable, "Any text")
SO, again, when i test it in the query designer it works fine, but when i run my application like the way i described above it doesn't give back any records all the time.
Does anybody have an idea ??
Thnx
Re: Problem with SQL statement
Although you've set the parameters value = CType PARAMACHTERNAAM,String), you never set it's name. Normally thios get's set when you create it but I think in your case it's getting created implicitely and unnamed when you set it's value. Try changing
VB Code:
Me.Adapter.SelectCommand.Parameters(0).Value = CType(PARAMACHTERNAAM,String)
to
VB Code:
Me.Adapter.SelectCommand.createParameter("param_lastname",adVarchar, adInput)
Me.Adapter.SelectCommand.Parameters("param_lastname").Value = CType(PARAMACHTERNAAM,String)