This is a migrated thread and some comments may be shown as answers.

Difficulty Inserting row using tableadapter

1 Answer 296 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 04 Aug 2010, 09:48 PM
I have a radgridview on a winform that is bound to a tableadapter.

I have the following code in the CellEndEdit Event:

 

 

private void grdPeople_CellEndEdit(object sender, GridViewCellEventArgs e)
       {
           try
           {
               this.Validate();
               this.peopleBindingSource.EndEdit();
               this.peopleTableAdapter.Update(peopleDAL);
                 
           }
           catch (System.Exception ex)
           {
               MessageBox.Show("Update failed:"+ex.Message);
           }
            
       }

The problem is when I click the "Click here to Add a New Row" and fill in the row, the Adapter.Update gets called but nothing is inserted into the database when I leave the row. I can step through the code and it steps over the Update, and no error is raised - yet there is no data in the database.  If I navigate off of the row, then navigate BACK to the row and update it, then the
INSERT command is fired cause I can see it in the database when I do a trace.  

So what I need to know is where is the right place to put a call to the Adapter.Insert Method?  I don't know what event to use.

I know I can create a new set of textboxes and checkboxes tro mimic my record and have a "Click to INsert" button with some code behind that, but I want to use the default functionality of the RadGrid.

Having said that - what is the recommended way to bind radGridViews to a SQL database?  I use TableAdapters because I come from an ASP .NET background and they work well there - but is there a better way to do it in Winforms?  Should I be using LINQ?

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 10 Aug 2010, 01:48 PM
Hello Eric,

Thank you for the question.

You can use the UserAddedRow event in your case:

void radGridView1_UserAddedRow(object sender, GridViewRowEventArgs e)
{
    try
    {
        this.Validate();
        this.peopleBindingSource.EndEdit();
        this.peopleTableAdapter.Update(peopleDAL);
   
    }
    catch (System.Exception ex)
    {
        MessageBox.Show("Update failed:" + ex.Message);
    }
}

I hope this helps. Let me know if you have additional queries.

Kind regards,
Julian Benkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or