none
Insert new row using BindingSource RRS feed

  • Question

  • I want to insert a row using BinsingSource.

    this peace of code failed.

    this.bindingSource.Insert(this.bindingSource.Position, this.bindingSource.Current);
    this.bindingSource.EndEdit();

    i don't want use table.add method.


    Tuesday, August 28, 2007 10:13 AM

Answers

  • If your bindingSource is a datatable,
    i dont think u can insert a new row at a particular position...(maybe i am wrong ?? )

    however, u can edit a row at a particular position using BeginEdit() and EndEdit(),

    e.g.:

    Code Snippet

    DataRow dr = bindingSource.Rows[IntPosition];
    dr.BeginEdit();
    dr[1] = "New Value";
    dr.EndEdit();




    Tuesday, August 28, 2007 12:17 PM

All replies

  • If your bindingSource is a datatable,
    i dont think u can insert a new row at a particular position...(maybe i am wrong ?? )

    however, u can edit a row at a particular position using BeginEdit() and EndEdit(),

    e.g.:

    Code Snippet

    DataRow dr = bindingSource.Rows[IntPosition];
    dr.BeginEdit();
    dr[1] = "New Value";
    dr.EndEdit();




    Tuesday, August 28, 2007 12:17 PM
  • Hi,

     

    You need to start the editing (insert) process by

    bindingSource1.AddNew();

    Then at suitable place you should do the following steps

    bindingSource1.EndEdit();
    //Get the dataset first

    DataSet1 ds = (DataSet1)bindingSource1.DataSource;


    //Then , refer to the table adapter (which would have been created when you create the binding source)
    userInfoTableAdapter.Update(ds);

    In short, while you endEdit , not only just end the edit, but also take steps to send the data to DB

     

    Hope this clears your doubt

    Monday, September 10, 2007 6:49 AM