插入命令 OLE 参数化
解决方案的当前进展:
这是更新后的代码:
sql = "INSERT INTO Strings (String_Name, Long_Text, Short_Text, Alternate_Text, Multi_String_ID, Lang_ID) VALUES (?,?, ?,?,?,?)"
Dim command = New OleDbCommand(sql, pConn)
command.Parameters.AddWithValue("@webStringName", "String_Name")
command.Parameters.AddWithValue("@webLang_String", "Long_Text")
command.Parameters.AddWithValue("@ptsShortText", "Short_Text")
command.Parameters.AddWithValue("@webAltText", "Alternate_Text")
command.Parameters.AddWithValue("@webMultiStringID", "Multi_String_ID")
将上面的行更改为... command.Parameters.AddWithValue("@webMultiStringID", OleDbType.Integer).Value = webMultiStringID
command.Parameters.AddWithValue("@webLang_Code", "Lang_ID")
command.ExecuteNonQuery()
ORIG POST:
我正在尝试使用 OLE 适配器创建和 INSERT 语句。我让它在没有参数的情况下工作,但现在我尝试添加参数并且遇到语法问题。哈
这是到目前为止的代码...
command = New OleDbCommand(sql, pConn)
sql = "INSERT INTO Strings (String_Name, Long_Text, Short_Text) VALUES (?,?, """ & ptsShortText & """)"
command.Parameters.Add("@webStringName", OleDbType.VarChar, 250, "String_Name")
command.Parameters.Add("@webLang_String", OleDbType.VarChar, 250, "Long_Text")
command = New OleDbCommand(sql, pConn)
command.ExecuteNonQuery()
只是试图将前两个变量参数化。
任何建议将不胜感激。
编辑:修复SQL
CURRENT PROGRESS TOWARD SOLUTION:
This is the updated code:
sql = "INSERT INTO Strings (String_Name, Long_Text, Short_Text, Alternate_Text, Multi_String_ID, Lang_ID) VALUES (?,?, ?,?,?,?)"
Dim command = New OleDbCommand(sql, pConn)
command.Parameters.AddWithValue("@webStringName", "String_Name")
command.Parameters.AddWithValue("@webLang_String", "Long_Text")
command.Parameters.AddWithValue("@ptsShortText", "Short_Text")
command.Parameters.AddWithValue("@webAltText", "Alternate_Text")
command.Parameters.AddWithValue("@webMultiStringID", "Multi_String_ID")
Changed above line to this...
command.Parameters.AddWithValue("@webMultiStringID", OleDbType.Integer).Value = webMultiStringID
command.Parameters.AddWithValue("@webLang_Code", "Lang_ID")
command.ExecuteNonQuery()
ORIG POST:
I am trying to create and INSERT statement with and OLE adapter. I had it working without paramtersm but now I am trying to add parms and am having issues with the syntax. Ha
Here is the code so far...
command = New OleDbCommand(sql, pConn)
sql = "INSERT INTO Strings (String_Name, Long_Text, Short_Text) VALUES (?,?, """ & ptsShortText & """)"
command.Parameters.Add("@webStringName", OleDbType.VarChar, 250, "String_Name")
command.Parameters.Add("@webLang_String", OleDbType.VarChar, 250, "Long_Text")
command = New OleDbCommand(sql, pConn)
command.ExecuteNonQuery()
Was just trying to get the first two variables parameterized.
Any suggestions would be greatly appreciated.
EDIT: Fixed SQL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你做错了什么。首先添加参数:
然后然后用新命令替换该命令(不带参数):
因此,您删除了该行中的所有现有参数。这就是为什么它不起作用。
您必须按照正确的顺序进行操作:
You are doing something wrong. You first add the parameters:
and then replace the command with a new one (with no parameters):
Thus, you remove all your existing parameters in this line. That's why it doesn't work.
You have to do it in the correct order: