Link to home
Start Free TrialLog in
Avatar of NoraWil
NoraWilFlag for Belgium

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.

   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

Open in new window


What am I doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NoraWil

ASKER

Sometimes is simplier than expected.
Thanks.