DataBinding & Update

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • havana7
    New Member
    • Jul 2007
    • 13

    DataBinding & Update

    Hi people,
    I'm a newbie in C# Development.

    I have a problem with these lines of code:

    ...
    SqlConnection c = new SqlConnection(M ainForm.connect ion);
    c.Open();
    SqlCommand cmd = new SqlCommand("SEL ECT id, ragione_sociale , indirizzo, cap, città, provincia FROM cliente", c);
    c.Close();
    da = new SqlDataAdapter( cmd);
    SqlCommandBuild er cb = new SqlCommandBuild er(da);
    ds = new DataSet();da.Fi ll(ds,"cliente" );

    // textBox
    txtId.DataBindi ngs.Add("Text", ds,"cliente.id" );
    txtRagione_soci ale.DataBinding s.Add("Text",ds ,"cliente.ragio ne_sociale");
    }

    // Simple button SAVE in the form
    void Button1Click(ob ject sender, EventArgs e)
    {
    da.Update(ds, "cliente");
    this.Close();
    }


    Why this lines doesn't update database after modify textBox???
    I've used Update command in many parts of my application and it works fine (i.e. DataGridView).

    Thank you!!!
  • havana7
    New Member
    • Jul 2007
    • 13

    #2
    BindingContext[ds, "cliente"].EndCurrentEdit ();

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      Welcome to TSDN. The problem may be that your update occurs in an event unrelated to your command function. HTH.

      Comment

      • havana7
        New Member
        • Jul 2007
        • 13

        #4
        Thank you very much but I've solved my problem with this line:
        BindingContext[ds, "cliente"].EndCurrentEdit ();

        Comment

        Working...