0

I have two textboxes and I want to store their values into an SQL database table.

however, I get the error for the command text

Additional information: Incorrect syntax near '+'.

I dont know wether I am using the wrong syntax to combine the two values from the two textboxes or do I need another SQL statement for the second text box?

1 Answer 1

1

Likely the problem lies with your command text. Try something like

 cmd.CommandText = "INSERT INTO MemberInformation(Name, Age) VALUES(@nm, Age)";

You might also be better off doing the string concatenation before adding them to the database. Personally, I would replace the cmd.Parameters.AddWithValue("@nm", textBox1.Text + textBox2.Text); with

string val = string.Concat(textBox1.Text, textBox2.Text);
cmd.Parameters.AddWithValue("@nm", val);

or maybe just

cmd.Parameters.AddWithValue("@nm",string.Concat(textBox1.Text, textBox2.Text));

if it works.

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

Comments

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.