title: Updating Database using Datagrid in C#
body: <p>just working on the something lately need help i m again stuck here.... i m retrieving values from database using datagrid and i want to update the database using that similar datagrid but somehow i m having trouble, can anyone guide me how to do that..... i mean when the query is executed and selected data is retrieved if the user wants to update something he/she can do it at the datagrid in which value is being displayed....</p>
  
  <pre><code>if (textBox1.Text != ""|| textBox1.Text==null)
          {
              textBox3.Enabled = false;
              dateTimePicker1.Enabled = false;
              dateTimePicker2.Enabled = false;
              String txt = textBox1.Text;
              dataGridView1.DataSource = null;
              dataGridView1.Rows.Clear();
              dataGridView1.Refresh();
  
              OleDbDataAdapter dAdapter = new OleDbDataAdapter("SELECT * FROM [BDetails] WHERE ([BranchCode] = '" + @txt + "')", connParam);
              OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
  
  
               dataTable = new DataTable();
              DataSet ds = new DataSet();
  
              dAdapter.Fill(dataTable);
  
              if (dataTable.Rows.Count &gt; 0)
              {
                  for (int i = 0; i &lt; dataTable.Rows.Count; i++)
                  {
                      dataGridView1.Rows.Add(dataTable.Rows[i][0], dataTable.Rows[i][1], dataTable.Rows[i][2], dataTable.Rows[i][3], dataTable.Rows[i][4], dataTable.Rows[i][5], dataTable.Rows[i][6], dataTable.Rows[i][7], dataTable.Rows[i][8], dataTable.Rows[i][11], dataTable.Rows[i][12]);
  
                  }
  
              }// end inner if
              else
              {
                  MessageBox.Show("No Record Found");
                  textBox3.Enabled = true;
                  dateTimePicker1.Enabled = true;
                  dateTimePicker2.Enabled = true;
              }// end inner else
  
  
          }// end outer if
          else 
          {
              MessageBox.Show("Please Enter Branch Code");
              bookConn.Close();
  
          }// end outer else
  </code></pre>
  
  <p>i m desperate guys help me</p>
  
  <p>private void button8_Click(object sender, EventArgs e)
          {
              ReadData();
             // SaveData();</p>
  
  <pre><code>    }// end function
  
      void ReadData()
      {
          this.ds = new DataSet();
        //  string connString = "CONNICTION STRING GOES HERE";
          dAdapter = new OleDbDataAdapter("select * from BDetails", connParam);
          this.dAdapter.Fill(this.ds,"[BDetails]");
          this.ds.AcceptChanges();
          //set the table as the datasource for the grid in order to show that data in the grid
          this.dataGridView1.DataSource = ds.DefaultViewManager;
      }// end function
  
      void SaveData()
      {
          DataSet changes = this.ds.GetChanges();
          if (changes != null)
          {
              //Data has changes. 
              //use update method in the adapter. it should update your datasource
              int updatedRows = this.dAdapter.Update(changes);
              this.ds.AcceptChanges();
          }
      }// end function
  </code></pre>