Implementing CRUD in the Infragistics XamDataGrid

Kiril Matev / Friday, February 25, 2011

Say you've just downloaded the trial version of Infragistics WPF Line of Business product, featuring our fully-featured and high-performance XamDataGrid. Every scenario you implement with it would involve CRUD operations. We recognized the importance of this topic by a webinar we held. Please view our webinars page for information on upcoming webinars, and recordings of past ones.

Here's a brief summary of the types of datasources bound to in the sample and the generated and custom code we used.

Xml Data Binding

Using an XmlDataProvider, we were able to bind the XamDataGrid to the contents of an XML file, only setting the Source and Path attributes.

ADO.NET Entity Model Binding

We created an entity model, generating it from the database. We then dragged it from the data sources snap-in into the visual area, producing a bound XamDataGrid. The code for reading data was automatically generated by Visual Studio. In order to implement adding/deleting/updating records, we need to handle the RecordAdded, RecordUpdated, RecordsDeleted events, calling the SaveChanges method of the model, forcing it to push changes down to the underlying data source.

DataSet Binding

Start by creating a dataset using Visual Studio based on a table from the database. The dataset will then appear in the data sources snap-in in Visual Studio. Drag and drop it into the visual area. This will produce a bound grid, with code for reading data automatically generated. Again, in order to implement adding/deleting/updating records, we need to handle the RecordAdded, RecordUpdated, RecordsDeleted events, calling the Update method of the table adapter, providing it with the dataset as an argument, forcing it to save the changes to the underlying data source.

LinqToSql Binding

Generate entity classes using the Linq To Sql classes object. Then set the Employees table of the created data context to the DataSource property of the XamDataGrid. Then implement adding/deleting/updating records, by handling the RecordAdded, RecordUpdated, RecordsDeleted events. In each of them, call the SubmitChanges method of the data context object, forcing it to save the changes to the underlying data source.

Summary

During the webinar, I explained and demonstrated how to implement the CRUD operations using the XamDataGrid. I hope the recording and the sample project available in this blog post will be valuable for you in your work. 

If you have any questions, please email me at kmatev@infragistics.com