Ajit N

Ajit N

  • NA
  • 352
  • 71.3k

How to update data in DataGridView based on condition in sql

Jul 8 2018 5:17 AM
Hello, i want to update record ( based on condtion in sql query ) from DataGridView. i used the update method and i tried some code but it shows me below error on update method
 
OleDbCommand.Prepare method requires all parameters to have an explicitly set type.
  1. OleDbDataAdapter da;  
  2.  DataSet ds = null;  
  3.  BindingSource bsource = new BindingSource();  
  4.   
  5. ublic void BindData()  
  6.        {  
  7.   
  8.            OleDbCommand cmd = new OleDbCommand("select srno,AccNumber,Admission_Fee,Family_fund,MonthlyCollection,MonthlyDeposit,Fund,SimpleLoanBal,SimpleInstallment,SimpleInt,UrgentLoanBal,UrgentInstallment,UrgentInt,EducationLoanBal,EducationInstallment,EducationInt,GuarantorInstallment,GuarantorInt,OtherLoanBal,OtherInstallment,OtherInt,BankLoanBal,BankInstallment,BankInt,TotalInstallment,OtherLoanCaption from transDemand where IssueDate=@IssueDate order by AccNumber Desc", con);  
  9.            cmd.Parameters.AddWithValue("@IssueDate", datesearch.Value.ToString("dd-MM-yyyy"));  
  10.            da = new OleDbDataAdapter(cmd);  
  11.            ds = new DataSet();  
  12.            OleDbCommandBuilder cmdbuild = new OleDbCommandBuilder(da);  
  13.            da.Fill(ds, "transDemand");  
  14.            bsource.DataSource = ds.Tables["transDemand"];  
  15.            dataGridView1.DataSource = bsource;  
  16.   
  17.   
  18. private void btnupdate_Click(object sender, EventArgs e)  
  19.        {  
  20.   
  21.            DataTable dt = ds.Tables["transDemand"];  
  22.            this.dataGridView1.BindingContext[dt].EndCurrentEdit();  
  23.            this.da.Update(dt);  
  24.   
  25.            BindData();  
  26.        }

Answers (5)