1

I have a WPF form with a button.

There is a textbox under the button and I want the .text to go into a list box

2
  • "Not performing the desired result"? Your SQL doesn't look valid. What is the current result? Does the app crash / throw an exception? Commented Mar 15, 2017 at 23:54
  • You should really consider databinding that textbox text if its a permanent feature of this app you are writing. Commented Mar 15, 2017 at 23:56

1 Answer 1

2

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:

...
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.

Sign up to request clarification or add additional context in comments.

1 Comment

If we're going to use a parameter for TimesClicked, we should also use one for ButtonName.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.