Best Practice for Adding a new row to a DataGrid?

Discussion in 'ASP .Net' started by Paul, Dec 25, 2003.

  1. Paul

    Paul Guest

    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



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Paul, Dec 25, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Praveen Balanagendra via .NET 247
    Replies:
    2
    Views:
    4,093
  2. =?Utf-8?B?U3VyZXNo?=
    Replies:
    1
    Views:
    469
    Saravana
    Nov 22, 2004
  3. Luis Esteban Valencia
    Replies:
    0
    Views:
    686
    Luis Esteban Valencia
    Jan 11, 2005
  4. D
    Replies:
    0
    Views:
    220
  5. oldyork90
    Replies:
    1
    Views:
    161
    Jeremy J Starcher
    Sep 10, 2008
Loading...

Share This Page