title: How to update MS Access database
body: <p>I need a simple program to update MS Access database fields. I followed an <a href="http://homeandlearn.co.uk/csharp/csharp_s12p4.html" rel="nofollow">online tutorial</a> which was simple and had the code working. But it doesnt seem to work anymore when I reimplement it. Here's my code.</p>
  
  <pre><code> public partial class Form1 : Form
   {
      public Form1()
      {
          InitializeComponent();
      }
  
      OleDbConnection conn;
      OleDbDataAdapter da;
      DataSet ds;
      OleDbCommandBuilder cb;
      DataRow row;
  
      private void Form1_Load(object sender, EventArgs e)
      {
          conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = C:\\test.mdb");
          da = new OleDbDataAdapter("select* from user", conn);
          ds = new DataSet();
  
          conn.Open();
          da.Fill(ds, "user");
          conn.Close();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          cb = new OleDbCommandBuilder(da);
          row = ds.Tables["user"].Rows[0];
  
          row[3] = "hello";
  
          da.Update(ds, "user");
      }
  }
  </code></pre>
  
  <p><code>user</code> is the table name of my database. What I tried to do is update the field row[0] (first row) and column[3] (4th column) with the string <code>hello</code>.. The error i get is <code>Synatx error in FROM clause</code>. After some internet reading, I found <code>user</code> has to be in square brackets. So I made it this.</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
  
      OleDbConnection conn;
      OleDbDataAdapter da;
      DataSet ds;
      OleDbCommandBuilder cb;
      DataRow row;
  
      private void Form1_Load(object sender, EventArgs e)
      {
          conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = C:\\test.mdb");
          da = new OleDbDataAdapter("select* from [user]", conn);
          ds = new DataSet();
  
          conn.Open();
          da.Fill(ds, "user");
          conn.Close();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          cb = new OleDbCommandBuilder(da);
          row = ds.Tables["user"].Rows[0];
  
          row[3] = "hello";
  
          da.Update(ds, "user");
      }
  }
  </code></pre>
  
  <p>When I do this, I get a new error, <code>Syntax error in UPDATE statement</code>. I did a lot of internet reading but none seems to address this. They all have used <code>Update</code> command differently. I know only this way. What's wrong in my code? Especially since this worked before. Or isn't this way of updating a proper technique? Please help me with the code and not technical terms which I don't follow. Or any other procedure to update in ms access?</p>
  
  <p>Thanks. </p>