Prepared Statements For ODBC in VB.net

帅比萌擦擦* 提交于 2019-12-08 12:04:23

问题


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?


回答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



来源:https://stackoverflow.com/questions/2027050/prepared-statements-for-odbc-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!