Re: Typed DataTable - NewRow() - Identity Field



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 ?!






.



Relevant Pages

  • Re: Designfrage Client/ Server Applikation (SQL Server 2000)
    ... vom SQL Server 2000. ... fetch durch die Tabelle (Select SQLSTRING, DATUM, AKTIV FROM ... TABELLE) ... aber noch an den Output rankommen, um ihn per E-Mail zu versenden. ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)
  • Re: Help
    ... Wayne Snyder, MCDBA, SQL Server MVP ... > declare @i varchar ... >>fetch next from test into @tbnames ...
    (microsoft.public.sqlserver.server)
  • Re: Typed DataTable - NewRow() - Identity Field
    ... I am not using my custom insert command, ... When you synch with the database you should have the data adaptor fetch ... The insert command would read something like (assuming your sql command ... Use for the identitiyfield a Guid ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Server-side cursors for ResultSets - a pattern? (and what about Oracle?)
    ... Setting a fetch size is OK, ... I don't know if this applies to SQL Server 2000 (and I'm using, ... the SQL Server 2005 JDBC drivers). ... as I get a JVM error saying that I exceed the ...
    (comp.lang.java.databases)
  • Re: Attempt to initiate a new SQL Server operation with results pending.
    ... >>I took a Perl-Gtk2 app which has been running fine, ... >>initiate a new SQL Server operation with results pending. ... The application gives the 'Attempt to initiate a new SQL Server ... It *should* fetch each row and dump the values to the ...
    (perl.dbi.users)