将数据插入数据库时​​显示错误“语法不正确”吗?

时间:2019-07-11 07:46:12

标签: c# asp.net sql-server

var command = "insert into User values(@Emp_Id,@Honorific,@F_Name,@L_Name,@Password,@Designation,@Level,@Email,@Mobile,@Department,@Date_Joining,@Creation_Date)";

        using (SqlConnection cnn = new SqlConnection(cnnString))
        {

            using (SqlCommand cmd = new SqlCommand(command, cnn))
            {
                cmd.Parameters.AddWithValue("@Emp_ID", TB_EC_NO.Text);
                cmd.Parameters.AddWithValue("@Honorific", DD_Honorific.SelectedValue);
                cmd.Parameters.AddWithValue("@F_Name", TB_First_Name.Text);
                cmd.Parameters.AddWithValue("@L_Name", TB_Last_Name.Text);
                cmd.Parameters.AddWithValue("@Password", TB_Password.Text);
                cmd.Parameters.AddWithValue("@Designation", DD_Designation.SelectedValue);
                cmd.Parameters.AddWithValue("@Level", "Level");
                cmd.Parameters.AddWithValue("@Email", TB_Email.Text);
                cmd.Parameters.AddWithValue("@Mobile", TB_Mobile.Text);
                cmd.Parameters.AddWithValue("@Department", DD_Department.SelectedValue);
                cmd.Parameters.AddWithValue("@Date_Joining", DateTime.Now);
                cmd.Parameters.AddWithValue("@Creation_Date",DateTime.Now);

                cnn.Open();
                cmd.ExecuteNonQuery();
            }
        }

0 个答案:

没有答案