Groups | Blog | Home
all groups > dotnet ado.net > january 2007 >

dotnet ado.net : How to update a dataset table row I have previously added ?


Bishman
1/31/2007 10:41:10 AM
Hi,

C# App. VS2005

I have a detail table ordered descending on a field called DetailRowID

ie
ArrayIndex Detail RowID
0 3
1 2
2 1

I add a new row but it goes to the end of the dataset so does not

ArrayIndex Detail RowID
0 3
1 2
2 1
3 4

I then need to subsequently update the row I have just added. What is the
proper way to refer to that row ? I usually set the field values using
DatasetName.TableName[0].Fieldname notation, however that is the previously
entered row (Index=0) and not the one just added (Index = 3). Do I need to
refresh the dataset table so my new row is at index 0 and then I know where
it is - or just work out the index value of the new record by using the
number of rows in the DS before I added my new one, or neither ? I
appreciate this is probably totally wrong however I havent got to grips with
databinding yet and just need to get this done !

Thanks,

Jon

Earl
2/2/2007 12:26:01 AM
This seems to be a common question lately. I'm assuming your DetailRowID is
an autoincrement. The simplest technique is to use a negative autoincrement
in the datatable in order to determine which rows are newly added. So your
rows might look like:

DetailRowID
2 (existing)
3 (existing)
1 (existing)
-1 (new)

[quoted text, click to view]

AddThis Social Bookmark Button