Results 1 to 2 of 2

Thread: Problem with SQL statement

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    4

    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

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    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:
    1. Me.Adapter.SelectCommand.Parameters(0).Value = CType(PARAMACHTERNAAM,String)
    to
    VB Code:
    1. Me.Adapter.SelectCommand.createParameter("param_lastname",adVarchar, adInput)
    2. Me.Adapter.SelectCommand.Parameters("param_lastname").Value = CType(PARAMACHTERNAAM,String)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width