Share via

Updating database c# code explanation

Rudi Hartono 116 Reputation points
2020-10-15T06:43:59.433+00:00

Hi guys,

I am very thankful if anybody can explain what is happening with these few lines.

  private void button3_Click(object sender, EventArgs e)
  {
      try
      {
          SqlCommandBuilder customeradaptorcommand = new SqlCommandBuilder(adaptorcustomer);
          adaptorcustomer.Update(tabelcustomer);
      }
      catch (Exception ex)
      {
          MessageBox.Show("error" + ex.Message, "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }

above one doesnt work, but below one is good

    private void button3_Click(object sender, EventArgs e)
    {
        try
        {
            SqlCommandBuilder customeradaptorcommand = new SqlCommandBuilder(adaptorcustomer);
            this.managercustomer.EndCurrentEdit();
            adaptorcustomer.InsertCommand = customeradaptorcommand.GetInsertCommand();
            this.adaptorcustomer.Update(this.tabelcustomer);
            commandcustomer.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            MessageBox.Show("error" + ex.Message, "Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

the part that making me confused is why i need to create another customeradaptorcommand which i didnt use it when using Update command.

Community Center | Not monitored
0 comments No comments

1 answer

Sort by: Most helpful
  1. RLWA32 52,571 Reputation points
    2020-10-15T09:31:34.533+00:00

    Questions regarding C# code should be posted in this MSDN Forum - Visual C#

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.