简体   繁体   English

使用C#WPF在按钮单击事件中使用文本框值更新SQL条目

[英]Update SQL entry using textbox values on button click event using C# WPF

I have a WPF form with a button. 我有一个带有按钮的WPF表单。

There is a textbox under the button and I want the .text to go into a list box 按钮下方有一个文本框,我希望.text进入列表框

The syntax for your update command should be something like this, note that you haven't mentioned the name of the table in the database which is storing the data, so I've just called it ButtonTable : update命令的语法应类似于以下内容,请注意,您尚未在存储数据的数据库中提及表的名称,因此我将其ButtonTable

...
cmd.CommandText = "UPDATE [ButtonTable] SET [TimesClicked] = @nm WHERE [ButtonName] = @buttonName;";
cmd.Parameters.Add("@buttonName", SqlDbType.VarChar, 100).Value = "Button1";
cmd.Parameters.Add("@nm", SqlDbType.Int).Value = textBox1.Text;
...

Also, I recommend specifying the type of your parameters as in the above sample. 另外,我建议像上面的示例中那样指定参数的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM