以下代码中“)”附近的语法错误不正确

时间:2016-06-03 14:51:18

标签: asp.net

SqlCommand cmd = new SqlCommand("insert into Hospdb(@PatientId,@PatientName,@Password,@Emailid,@ContactNumber,@Address)", con);
        cmd.Parameters.AddWithValue("@PatientId", txtPatID.Text);
        cmd.Parameters.AddWithValue("@PatientName", txtPatName.Text);
        cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
        cmd.Parameters.AddWithValue("@Emailid", txtEmailId.Text);
        cmd.Parameters.AddWithValue("@ContactNumber",txtContactNumber.Text);
        cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
        cmd.ExecuteNonQuery();

1 个答案:

答案 0 :(得分:0)

你的Insert语句错了!有关详细信息,请查看以下MSDN链接:

MSDN Insert Statement Syntax

MSDN Insert statement with SQLCommand

您需要将其编写如下:

    SqlCommand cmd = new SqlCommand("Insert into [Hospdb] ([PatientId], [PatientName],[Password],[Emailid],[ContactNumber],[Address]) 
    Values (@PatientId,@PatientName,@Password,@Emailid,@ContactNumber,@Address)", con);
            cmd.Parameters.AddWithValue("@PatientId", txtPatID.Text);
            cmd.Parameters.AddWithValue("@PatientName", txtPatName.Text);
            cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
            cmd.Parameters.AddWithValue("@Emailid", txtEmailId.Text);
            cmd.Parameters.AddWithValue("@ContactNumber",txtContactNumber.Text);
            cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
            cmd.ExecuteNonQuery();