下面是我的更新查询,它工作正常,但是当我在参数字段中添加int DrId
(最后)以检查条件,在此之后它显示我跟随错误
No value given for one or more required parameters.
错误在哪里,因为DrId
是我的主键,我不会更新它
public bool UpdateDrMaster(string title, string FirstName, string Mname, string lastName, string regNo, string speciality, string contactNo1, string contactNo2, string city, string addrss, string pincode, string emailId, string fee_unit, string fee, string DrType, bool displayType,int DrId)
{
bool flag = false;
try
{
string sql = "UPDATE Doctor_Master SET [Title]=@Title,[FirstName]=@FirstName,[MiddleName]=@MiddleName,[LastName]=@LastName,[RegistrationNo]=@RegistrationNo,[Speciality]=@Speciality,[ContactNo_1]=@ContactNo_1,[ContactNo_2]=@ContactNo_2,[City]=@City,[Address]=@Address,[Pincode]=@Pincode,[Email_ID]=@Email_ID,[Fee_Unit]=@Fee_Unit,[Fee]=@Fee,[Type_of_Dr]=@Type_of_Dr,[Display]=@Display,[Hide_Date]=@Hide_Date WHERE Doctor_ID=" +DrId;
cmd = new OleDbCommand(sql, acccon);
cmd.Parameters.AddWithValue("@Title", title);
cmd.Parameters.AddWithValue("@FirstName", FirstName);
cmd.Parameters.AddWithValue("@MiddleName", Mname);
cmd.Parameters.AddWithValue("@LastName", lastName);
cmd.Parameters.AddWithValue("@RegistrationNo", regNo);
cmd.Parameters.AddWithValue("@Speciality", speciality);
cmd.Parameters.AddWithValue("@ContactNo_1", contactNo1);
cmd.Parameters.AddWithValue("@ContactNo_2", contactNo2);
cmd.Parameters.AddWithValue("@City", city);
cmd.Parameters.AddWithValue("@Address", addrss);
cmd.Parameters.AddWithValue("@Pincode", pincode);
cmd.Parameters.AddWithValue("@Email_ID", emailId);
cmd.Parameters.AddWithValue("@Fee_Unit", fee_unit);
cmd.Parameters.AddWithValue("@Fee", fee);
cmd.Parameters.AddWithValue("@Type_of_Dr", DrType);
cmd.Parameters.AddWithValue("@Display", displayType);
cmd.Parameters.AddWithValue("@Hide_Date", System.DateTime.Now.ToShortDateString());
cmd.ExecuteNonQuery();
flag = true;
}
catch (Exception err)
{
MessageBox.Show(err.Message.ToString());
}
return flag;
}
答案 0 :(得分:1)
您的更新查询中有Doctor_Id
,但您没有为其设置值。即使你不打算更新它的值,你也必须为它设置一个值作为你的where clase的一部分。
string sql = "UPDATE Doctor_Master SET [Title]=@Title,[FirstName]=@FirstName,[MiddleName]=@MiddleName,[LastName]=@LastName,[RegistrationNo]=@RegistrationNo,[Speciality]=@Speciality,[ContactNo_1]=@ContactNo_1,[ContactNo_2]=@ContactNo_2,[City]=@City,[Address]=@Address,[Pincode]=@Pincode,[Email_ID]=@Email_ID,[Fee_Unit]=@Fee_Unit,[Fee]=@Fee,[Type_of_Dr]=@Type_of_Dr,[Display]=@Display,[Hide_Date]=@Hide_Date WHERE Doctor_ID=" +DrId;
答案 1 :(得分:1)
为什么不尝试这个!!!用你的参数名称替换?
public bool UpdateDrMaster(string title, string FirstName, string Mname,
string lastName, string regNo, string speciality, string contactNo1,
string contactNo2, string city, string addrss, string pincode, string emailId,
string fee_unit, string fee, string DrType, bool displayType,int DrId)
{
bool flag = false;
try
{
string sql = "UPDATE Doctor_Master SET Title=?FirstName=?,
MiddleName=?,LastName=?,RegistrationNo=?,Speciality=?,ContactNo_1=?,
ContactNo_2=?,City=?,Address=?,Pincode=?,Email_ID=?,Fee_Unit=?,Fee=?,
Type_of_Dr=?,Display=?,Hide_Date=? WHERE Doctor_ID=?";
cmd = new OleDbCommand(sql, acccon);
cmd.Parameters.AddWithValue("@Title", title);
cmd.Parameters.AddWithValue("@FirstName", FirstName);
cmd.Parameters.AddWithValue("@MiddleName", Mname);
cmd.Parameters.AddWithValue("@LastName", lastName);
cmd.Parameters.AddWithValue("@RegistrationNo", regNo);
cmd.Parameters.AddWithValue("@Speciality", speciality);
cmd.Parameters.AddWithValue("@ContactNo_1", contactNo1);
cmd.Parameters.AddWithValue("@ContactNo_2", contactNo2);
cmd.Parameters.AddWithValue("@City", city);
cmd.Parameters.AddWithValue("@Address", addrss);
cmd.Parameters.AddWithValue("@Pincode", pincode);
cmd.Parameters.AddWithValue("@Email_ID", emailId);
cmd.Parameters.AddWithValue("@Fee_Unit", fee_unit);
cmd.Parameters.AddWithValue("@Fee", fee);
cmd.Parameters.AddWithValue("@Type_of_Dr", DrType);
cmd.Parameters.AddWithValue("@Display", displayType);
cmd.Parameters.AddWithValue("@Hide_Date", System.DateTime.Now.ToShortDateString());
cmd.Parameters.AddWithValue("@DrId", DrId);
cmd.ExecuteNonQuery();
flag = true;
}
catch (Exception err)
{
MessageBox.Show(err.Message.ToString());
}
return flag;
}
将您的Db列名称与查询列匹配。查看是否有任何字符放错位置或拼写错误