A very simple class for a Person could look like this: If you’ve not seen the [ ] syntax before, these are Attributes.
This simple markup tells the compiler additional information about the entity, which is then used to generate additional code.
The IEquatable part isn’t something for the Grid View, but to help us manage our custom object.
This Interface has one method, Equals, which is used when comparing one object to another to determine if they are the same.
When using Data Sets and Table Adapters, everything is a dream, but when using your own custom objects the wizards and property pages act like you don’t exist.
The good news is with a little extra code, we can have our custom objects act just like fancy Data Sets.
I have no earthly idea why the Update command wants to update the key columns by default.
A very common Attribute is Serializable, which means the object can be saved. Data Object Field to markup the field for the Grid View.
A class marked [Serializable] would have code added to save and load a saved object automatically. The true parameter marks the field as a primary key, which will automatically add the field name to the “Data Key Names” list of the Grid View.
MDF database that gets created in App_Data when you select the Web Site Configuration Wizard, and I’m going to edit the aspnet_Roles table using a Grid View. Then expand its Update Command property and remove the key colums from the “UPDATE col1= @col1” portion of the query (e.g.
After creating a Table Adapter by adding a new Data Set to my project and creating the necessary Select, Update, Insert, and Delete columns, I wire up my Grid View to an Object Data Source that uses this Table Adapter resulting in code like this: suggests that the Data Key Names property should resolve this issue, but it does not, at least when the keys are Guid values rather than ints or strings (one of the forum posters suggested the Data Key Names collection doesn’t support object typed keys). Andrew Duthie has a summary of how to fix this issue on his blog (from 2005, no less). don’t remove the keys from the WHERE part of the query!!! You will also want to remove the key parameters from the Update Command’s Parameters collection.
So complex DAL objects which take a lot of time to set up are likely to need some thought or redesign before being used in an Object Data Source.