Click here to Skip to main content
14,691,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here is my code. I want to use parameters to pass the values to my queries.
Public Shared Function FillStates(ByVal strState As String) As DataSet
        Dim ds As New DataSet
        Dim da As New iDB2DataAdapter
        Dim cn As iDB2Connection = CreateConnection()
        Try
            If strState.Length <= 0 Then
                Dim cm As New iDB2Command("SELECT * FROM DEVSUSH.CLSTATES", cn)
                da.SelectCommand = cm
                da.Fill(ds)
            Else
                Dim cm As New iDB2Command("SELECT * FROM DEVSUSH.CLSTATES Where STCODE='@strState", cn)
                cm.Parameters.Add("@strState", iDB2DbType.iDB2VarChar).Value = strState

                da.SelectCommand = cm
                da.Fill(ds)
            End If


        Catch ex As Exception
            LogError.LogErrorIntoTextFile(ex, "FillStates()")
        Finally
            cn.Close()
        End Try
        Return ds
    End Function


I get an error saying
The SQL statement text is not valid.
Format exception.

Could someone help me with this?
Posted

1 solution

Take off the quote!
Dim cm As New iDB2Command("SELECT * FROM DEVSUSH.CLSTATES Where STCODE='@strState", cn)
Becomes
Dim cm As New iDB2Command("SELECT * FROM DEVSUSH.CLSTATES Where STCODE=@strState", cn)
   
Comments
sudevsu 9-Apr-15 15:08pm
   
Hehehe. So simple. I didn't see that quote there. Thank you.
sudevsu 9-Apr-15 15:08pm
   
Thank you OG
OriginalGriff 9-Apr-15 15:34pm
   
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900