Inserting values into a SQL Server database using ado.net via C#

后端 未结 5 2073
春和景丽
春和景丽 2020-12-02 23:47

I have created a simple program to insert values into the table [regist], but I keep getting the error

Incorrect syntax near \')\'

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 00:34

    you should remove last comma and as nrodic said your command is not correct.

    you should change it like this :

    SqlCommand cmd = new SqlCommand("INSERT INTO dbo.regist (" + " FirstName, Lastname, Username, Password, Age, Gender,Contact " + ") VALUES (" + " textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, comboBox1.Text,comboBox2.Text,textBox7.Text" + ")", cn);
    

提交回复
热议问题