Re: Typed DataTable - NewRow() - Identity Field
- From: Chris Chilvers <keeper@xxxxxxxxxxx>
- Date: Thu, 29 Jun 2006 00:29:54 +0100
If the field is labeled as an idenity column then the client should
assign a temporary unique value for working localy (for relationships).
When you synch with the database you should have the data adaptor fetch
the created row from the server which will contain the generated ID.
The insert command would read something like (assuming your sql command
type is text, not a stored procedure):
'Insert the new row and simultaniously fetch the newly inserted row
'this will include our id (the other advantage of this is it
'can fetch calculated fields, changes made by triggers, etc.
insert_command.CommandText = _
"INSERT INTO tbl (a, b, c) VALUES (@a, @b, @c)" _
& " SELECT (id, a, b, c) FROM tbl WHERE id = scope_identity"
'This instructs the data adaptor to use the first returned result as the
'rows new values
insert_command.UpdateRowSource = UpdateRowsource.FirstReturnedRecord
On Wed, 28 Jun 2006 11:34:07 +0200, "TheMaxx" <themaxxREMOVE@xxxxxx>
wrote:
Why do i need to worry about ID field on client, isn't SQL Server.
responsible for that?
"Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx> wrote in message
news:e$3El%23omGHA.2452@xxxxxxxxxxxxxxxxxxxxxxx
TheMax,
Use for the identitiyfield a Guid
MyRow.IdentityField = new Guid();
I hope this helps,
Cor
"TheMaxx" <themaxxREMOVE@xxxxxx> schreef in bericht
news:e7tef5$cr2$1@xxxxxxxxxxxxxxxxxxxxxx
ADO 2.0
When i do:
MyRow = MyDataTable.NewMyRow();
MyRow.IdentityField value equals last ID + 1
What if other user is doing the same thing and gets same ID
On DatatTableAdapter.Update both users will try to update with same ID.
I also did not expect IdentityField to have a value (or have it = 0)
because that value should be prvided by SQL Server, not in DataTable in
memory ?!
- Follow-Ups:
- Re: Typed DataTable - NewRow() - Identity Field
- From: TheMaxx
- Re: Typed DataTable - NewRow() - Identity Field
- References:
- Typed DataTable - NewRow() - Identity Field
- From: TheMaxx
- Re: Typed DataTable - NewRow() - Identity Field
- From: Cor Ligthert [MVP]
- Re: Typed DataTable - NewRow() - Identity Field
- From: TheMaxx
- Typed DataTable - NewRow() - Identity Field
- Prev by Date: How to specify the sort column of a GridView
- Next by Date: ExecuteNonQuery() returns -1
- Previous by thread: Re: Typed DataTable - NewRow() - Identity Field
- Next by thread: Re: Typed DataTable - NewRow() - Identity Field
- Index(es):
Relevant Pages
|
|