Best Practice for Adding a new row to a DataGrid?

P

Paul

I have a working system for AutoIncrementing a new row added to a
DataGrid but I keep feeling like it's a kludge. It depends on assigning
a zero to the Primary Key ID field when the row is added to the
DataTable. I use that zero for a couple of things when I go into
EditMode, like setting the RowFilter, etc. The good thing is that zero
is a unique number that would never be duplicated for the row ID of the
table.

I also use zero's existence to tell me whether to sort ASC or DESC for a
DataView sort because of the way it affects finding an index to the
DataTable row.

In the end, the column is set to AutoIncrement and it is mapped to a
Primary Key Identity field in the SQL DB, so the existence of the zero
in a new row isn't really necessary for an update or insert. I just
don't know of a better way to do things. I can't assign it a NULL value
since it's a Primary Key, so it looks like I have to assign it some
integer when I add the new row.

I insert with this zero and it is replaced by the SQL DB by a viable
number for the new row. I read this back in after the insert and
everything is looking good. I just don't trust what I'm doing.

Is this OK or is there a best practice for adding new rows to a grid
that I should know about? Thanks. ~Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top