44582

Getting error : No value given for one or more required parameters

Below Is my Update query ,it was working fine,but when I have added int DrId in parameter fields (at last) to check where condition,after this it is showing me following error

No value given for one or more required parameters. where is the mistake ,since DrId is my Primary Key I won't update it

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

Answer1:

You have Doctor_Id in your Update query but you are not setting a value for it. Even though you are not going to update its value you have to set a value for it as its part of your 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;

Answer2:

Why not try this one!!! Replace you parameter name with ?

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

Another Possible reason

Match your Db column name with the queries column. See if any character is misplaced or miss-spelled

Recommend

  • saving image clicked from camera or loaded from gallery in database and retrieving it
  • Before insert trigger
  • How to update rows in Database with values from data.frame in R conditionally
  • How to force Safari browser to disable icloud Keychain in member registration forms ?
  • CRTP compile detection with template composition
  • Sum of a activity
  • How would I right a select statement to query this database?
  • how to password protect the digitally signed pdf using iTextSharp?
  • How to fix IllegalStateException: Activity has been destroyed when showing Dialogfragment after rota
  • How can I submit a html form post that has several different iterated values?
  • How to add click event to dynamically added html element in typescript
  • UPDATE a column based on the value of another column in the same table
  • Sort properties given attribute paramter order
  • error in insert into statement
  • Save Grid View Textbox Data to database
  • Tensorflow - No module named '_pywrap_tensorflow_internal'
  • How to make my MediaPlayer Activity run in background?
  • How can I loop Through all the elements in .select statement in Linq
  • What should I pass from the controller to my view in ASP.NET MVC 4 with Entity Framework?
  • prepared statement
  • How to post JSON to a REST webservice in codenameone
  • Unlock android mobile with PIN code programmatically Selenium mobile automation
  • No mapping exists from object type System.Windows.Forms.DateTimePicker to a known managed provider n
  • PHP says “No Database selected” even after using mysqli_select_db()
  • Getting error : No value given for one or more required parameters
  • Django mod-python error
  • oracle duplicate rows based on a single column
  • Why cannot top level module be set to main in Hint
  • JPA - getting distinct value from one column
  • php regex remove digits
  • Add delivery info to query in SAP Crystal Reports
  • How can you tell if a Python program has anything to read from stdin?
  • Group by one column and Show all results from another column
  • Update a record where _id = :id with Mongoose
  • Bad request using file_get_contents for PUT request in PHP
  • Display issues when we change from one jquery mobile page to another in firefox
  • Dynamically accessing properties of knockoutjs observable array
  • To display the title for the current loaction in map in iphone
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • trying to dynamically update Highchart column chart but series undefined