“将文本框值插入SQL数据库时,System.Data.dll中出现'System.Data.SqlClient.SqlException'类型的未处理异常

时间:2017-02-22 18:37:47

标签: c# .net sql-server visual-studio

我是C#的完全菜鸟,他试图将用户输入各种文本框的值插入到SQL数据库中。具体来说,我正在创建一个帐户创建页面。调试并将值插入文本框/数据库时,我遇到上述错误。

其他信息包括

  

'@pword'附近的语法不正确。

如果需要任何其他信息,我可以提供。

    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();
    }
}

0 个答案:

没有答案
相关问题