NoraWil
asked on
Passing SQL parameters to Access database in Visual Basic 2010
Hi,
This is the way I am used to pass parameters to an SQL server database. This time I'm using an Access database and my code doesn't seem to work.
The @Id parameter is passed like it should be, but @strLatitude and @strLongitude are not.
Everything works when I hard code the latitude and longitude in the SQL command, but that is not what I want.
What am I doing wrong?
This is the way I am used to pass parameters to an SQL server database. This time I'm using an Access database and my code doesn't seem to work.
The @Id parameter is passed like it should be, but @strLatitude and @strLongitude are not.
Everything works when I hard code the latitude and longitude in the SQL command, but that is not what I want.
dim strSQL as string
dim strLongitude as string = "4.123456"
dim strLatitude as string = "51.123456"
strSQL = "UPDATE Bedrijven " & _
"SET Bdr_strLatitude = @strLatitude, " & _
" Bdr_strLongitude = @strLongitude " & _
"WHERE Bdr_Id = @Id;"
Using cmdSQL As OleDbCommand = New OleDbCommand(strSQL, CN)
cmdSQL.Parameters.Add("@Id", OleDbType.Integer).Value = Id
cmdSQL.Parameters.Add("@strLatitude", OleDbType.VarChar).Value = strLatitude
cmdSQL.Parameters.Add("@strLongitude", OleDbType.VarChar).Value = strLongitude
Try
If CN.State <> ConnectionState.Open Then CN.Open()
cmdSQL.ExecuteNonQuery()
Catch ex As Exception
Call Fout71(ex.Message)
Return
Finally
CN.Close()
End Try
End Using
What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.