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

grid update w/ edit form

1 Answer 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
ToltingColtAcres asked on 24 May 2012, 04:51 PM
I have implemented this project as a test project:

http://www.telerik.com/help/aspnet-ajax/grid-updating-inplace-and-editforms.html

When I edit records, the edits show up in the grid... but they do not update in the northwinds database.

How do I get the updated records to write to the northwinds mdb using this code example?

1 Answer, 1 is accepted

Sort by
0
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
answered on 24 May 2012, 06:03 PM
Figured this out. Had to add the following routine to the code:
private Boolean WriteTable()
{
    using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +
              System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Nwind.mdb")))
    {
        OleDbDataAdapter adapter = new OleDbDataAdapter();
        OleDbCommandBuilder builder = new OleDbCommandBuilder(adapter);
        adapter.SelectCommand = new OleDbCommand("SELECT TOP 10 OrderID, EmployeeID, OrderDate, ShipName FROM Orders", conn);
        adapter.Update(GridSource);
    }
    return true;
}

Then, at the end of the RadGrid1_UpdateCommand routine, I added a call to this function.

The example code online is very misleading. I spent several hours this morning mucking around with it trying to get it to update, thinking I was doing something wrong on my end (why retrieve data from a database to a grid and then allow the user to edit it unless the changes will be applied back to the database?) The more I thought about it, the more illogical the code example seemed, since the data connection was not persistant and it was not logical to expect updates applied thru the updatecommand routine would actually send data back to the database. Once starting down that line of reasoning, finding sample code on the 'net to take a datatable and then update a backend data source was fairly simple to find. The online code examples should do a better job with comments to explain what is happening and, IMO, should include a commented out block of code such as posted above to allow the user to see how to update the backend database, if they want.

WriteTable();

Tags
Grid
Asked by
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
Answers by
ToltingColtAcres
Top achievements
Rank 2
Veteran
Iron
Share this question
or