C# &引用;类型为';的未处理异常;System.Data.SqlClient.SqlException';发生在System.Data.dll中;将文本框值插入SQL数据库时
我完全不知道C#在试图将用户输入到各种文本框中的值插入SQL数据库中。具体来说,我正在创建一个帐户创建页面。在调试并将值插入文本框/数据库时,我遇到了上述错误 其他信息包括 “@pword”附近的语法不正确 如果需要任何其他信息,我可以提供C# &引用;类型为';的未处理异常;System.Data.SqlClient.SqlException';发生在System.Data.dll中;将文本框值插入SQL数据库时,c#,.net,sql-server,visual-studio,C#,.net,Sql Server,Visual Studio,我完全不知道C#在试图将用户输入到各种文本框中的值插入SQL数据库中。具体来说,我正在创建一个帐户创建页面。在调试并将值插入文本框/数据库时,我遇到了上述错误 其他信息包括 “@pword”附近的语法不正确 如果需要任何其他信息,我可以提供 private void button1_Click(object sender, EventArgs e) { SqlConnection connection = new SqlConnection("Data Sourc
private void button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("Data Source=DESKTOP-P3JSE1C;Initial Catalog=logins;Integrated Security=True");
{
SqlCommand ins = new SqlCommand("Insert into Users(userid, fullName, username, email, pword) Values(@userid, @fullName, @username, @email, @pword", connection) ;
ins.Parameters.AddWithValue("@userid", textBox1.Text);
ins.Parameters.AddWithValue("@fullName", textBox2.Text);
ins.Parameters.AddWithValue("@username", textBox3.Text);
ins.Parameters.AddWithValue("@email", textBox4.Text);
ins.Parameters.AddWithValue("@pword", textBox5.Text);
connection.Open();
ins.ExecuteNonQuery();
connection.Close();
}
}
@pwords后面缺少结束符,除了缺少结束括号之外。我假设的userid列是主键?如果是,则不应在文本框中输入。它应该由系统分配。