Implementing CRUD in the Infragistics XamDataGrid

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, and a recording of the webinar is available here. Please view our webinars page for information on upcoming webinars, and recordings of past ones.

During the webinar, I demonstrated how to bind a XamDataGrid to a variety of data sources, and how to implement CRUD operations using a sample project. This sample is now available for download (please unblock the ZIP archive from the properties window before extracting it). You will need .NET Framework 4 and Visual Studio 2010 to build and run it. The sample application will not connect to the sample data when you run it, because it references the database on the computer it was built on. You will need to create the same database and table using the MSSQL create script (available here), and then modify the connection strings that are used by the data sources to reference your local database.

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


Comments  (4 )

infragisticsMaster
on Mon, Aug 19 2013 12:32 PM

How can we connect to the webinar?

Ravi Ragampeta
on Mon, Sep 30 2013 10:28 AM

I have a question not in continuation to the above post, but related.

Can anyone , please let me know how can we bind a datatable to a xamdatagrid.

Thanks

David Ye
on Thu, Mar 6 2014 9:15 PM

sample download link is not working. Can you fix that? thx

Bryan Greenway
on Tue, May 20 2014 12:14 AM

The webinar is no longer available.  Can you repost?  I need some explanation of connecting an EF model to a xamdatagrid and doing CRUD.  

Add a Comment

Please Login or Register to add a comment.