0

my question is a pretty simple one, however I simply cannot see where i have gone wrong.

I just want to know how to create a prepared statement in VB. I know in java one would use ? and these would get replaced. I am aware that in VB you use @ParameterName. Basically my code gets down to where i use the prepare method and the error i get is that my syntax for my insert is incorrect. To me it seems that the parameter is not getting substituted in the insert statement

Eg.

Dim cmd As String = "insert into sites(id) values(@id)"
Dim odcmd As New OdbcCommand

odcmd.CommandText = cmd

odcmd.Parameters.Add("@id", OdbcType.Int)
odcmd.Parameters("@id").Value = 5

con.Open()
odcmd.Prepare()
odcmd.ExecuteNonQuery()
con.Close()

Any help?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
moonblade
  • 287
  • 1
  • 3
  • 13

1 Answers1

1

nevermind, solved it myself.

Dim cmd As String = "insert into sites(id) values(?)"

Seems that it still uses the question marks, contrary to what i have found on the web

moonblade
  • 287
  • 1
  • 3
  • 13
  • For the record: the placeholder you use depends on the database you talk to and the library you run it through (odbc vs ole vs native), not on the client language doing the talking. – Joel Coehoorn May 14 '12 at 18:52