Home All Groups Group Topic Archive Search About

How to update a dataset table row I have previously added ?

Author
31 Jan 2007 10:41 AM
Bishman
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

Author
2 Feb 2007 5:26 AM
Earl
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)

Show quote
"Bishman" <jonathan.bis***@btinternet.com> wrote in message
news:OES4ATSRHHA.2076@TK2MSFTNGP05.phx.gbl...
> 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
>

AddThis Social Bookmark Button