문제

I know someone have asked question about using prepared statement for ODBC at VB.NET at here (Prepared Statements For ODBC in VB.net). But it doesn't describe cleary for me how to add the parameter to that prepared statement.

Any help?

Tq

도움이 되었습니까?

해결책

You can try to add command parameter the way shown in the post you referred :

Dim cmd As String = "insert into sites(field1, field2) values(?,?)"
Dim odcmd As New OdbcCommand

odcmd.CommandText = cmd

odcmd.Parameters.Add("@field1", OdbcType.Int)
odcmd.Parameters("@field1").Value = 5
odcmd.Parameters.Add("@field2", OdbcType.Int)
odcmd.Parameters("@field2").Value = 8

But there is an important point to note, that isn't explained there :

The order in which OdbcParameter objects are added to the OdbcParameterCollection must directly correspond to the position of the question mark placeholder for the parameter in the command text.

Related question : Can ODBC parameter place holders be named?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top