解决方案在vb.net中的字符串中添加文本框
解决方案是什么,如果您看到下面的代码有一个值(2000),那么我想将其更改为文本框,以便我可以自定义值。
谢谢杰克
Dim sql As String = "update GSDTS as t1 inner join IFGTS as t2 on t1.[ITM] = t2.[ITM] set t1.[CIU] = t2.[PRSOBNET]+2000 WHERE GDN = 'A.04.01.002.001'AND PNM=@PNM"
Using conn As New OleDbConnection(cn),
cmd As New OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("@PNM", ComboBox1.SelectedValue)
conn.Open()
cmd.ExecuteNonQuery()
End Using
What is the solution if you see the code below there is a value (2000) then I want to change it to textbox so I can custom value.
Thanks
jack
Dim sql As String = "update GSDTS as t1 inner join IFGTS as t2 on t1.[ITM] = t2.[ITM] set t1.[CIU] = t2.[PRSOBNET]+2000 WHERE GDN = 'A.04.01.002.001'AND PNM=@PNM"
Using conn As New OleDbConnection(cn),
cmd As New OleDbCommand(sql, conn)
cmd.Parameters.AddWithValue("@PNM", ComboBox1.SelectedValue)
conn.Open()
cmd.ExecuteNonQuery()
End Using
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像在此处一样将另一个参数添加到查询中
,看看如何用单行添加替换addWithValue。 AddWithValue很危险,因为它可以在使用日期或小数时歪曲您的价值,并且效率降低了字符串
**重要**
您正在与OLEDB提供商合作。在这种情况下,应按照占位符出现在字符串中的占位符的顺序添加参数。因此,应在@pnm之前添加新参数,否则在执行查询时将以错误的顺序读取它们。
You can just add another parameter to your query like here
Also, take a look at how to replace AddWithValue with a single line Add. AddWithValue is dangerous because it can misrepresents your value when working with dates or decimals and it is inefficient with strings
** IMPORTANT **
You are working with the OleDb provider. In this context the parameters should be added in the same order in which their placeholders appear in the string. So the new parameter should be added before the @PNM one otherwise they will be read in the wrong order when the query is executed.
您的SQL语法对我所知道的任何RDBM都无法使用,也没有标记后端。这可能完全是因为它根本不工作的原因,您应该首先纠正它。
其次,请勿使用addWithValue,而是添加并明确指定您的数据类型。
话虽如此,例如,MS SQL Server作为后端:
请注意,可变声明的顺序与它们在查询中使用的顺序相同。这是OLEDB(位置论点)的必要条件。如果您的后端类似于MS SQL Server,则更喜欢使用特定的SQLConnection,SQLCommand(那么您也可以使用命名参数)。
Your SQL syntax wouldn't work for any RDBMS I know of and you didn't tag the backend. That might be solely a reason for it not to work at all, you should start by correcting it.
Second, do not use AddWithValue but Add and explicitly specify your data type.
Having said that, for example MS SQL server as a backend:
Note that order of variable declarations are same as their order they are used in the query. That is a necessity with OleDb (positional arguments). If your backend is something like MS SQL server then prefer using backend specific SqlConnection, SqlCommand (then you can also use named parameters).