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();
答案 0 :(得分:0)
你的Insert语句错了!有关详细信息,请查看以下MSDN链接:
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();