Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
.NET and @@identity
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00666202
Message ID:
00666352
Views:
20
Terry,
I have not found a way to get a PK when the commandtype is text. For what it's worth,I ended up making my insert routines stored procedures and specifying the PK as an output parameter. Not what I wanted to do in all cases but I couldn't find another way.

I'll be interested to see if someone else has found a way to pull it off when commandtype is text.

Chris


>Query looks like "insert into dealer(name, code, username, password, agent) values
>('X','Y','test','test',0)
>
>Dealer is table, and I'm not using Stored Procedures, but running first the insert statement and then immediately running the identity select in an ASP .NET session with a primary key field ID that is an identity with seed 1 increment 1.
>
>ds=sqlData.runsql("select @@identity from dealer","dealer"), doesn't work
>ds=sqlData.runsql("select scope_identity() from dealer","dealer"), doesn't work
>ds=sqlData.runsql("select ident_current('dealer')","dealer"), does work
>Then I use:
>dt=ds.tables(0)
>dim idy as integer = dt.rows(0)(0) to get the value and return it.
>The select used fill method of the dataadapter object.
>The insert uses executenonquery method of the command object.
>I understand somewhat the scope and session differences between these keywords, but don't understand why in .NET two don't work and the one does.
>
>
>
>Mike, have you seen the article in ASP Pro .NET by Dino Esposito on the SQLClient classes where he says most of the advantage of using Stored Procedures is gained by using these drivers vs Oledb?
>
>>You've not provided enough information. What's the query look like? What is "Dealer?" A table or stored procedure?
>>
>>I cannot think of any reason that ADO .NET would not be able to deal with @@IDENTIY?
>>
>>>.NET datatable doesn't return identity.
>>>
>>>ds=sqlData.runsql(strSql,"Dealer")
>>>dt=ds.tables(0)
>>>dim idx as integer = dt.rows(0)(0)
>>>return idx
>>>
>>>idx is dbnull always with .NET
>>>
>>>If I run the query in Query Analyzer, I get the proper id# for my auto-increment primary key id field right after running an INSERT command.
>>>
>>>Does .NET dataset not support the @@identity?
>>>
>>>How would I get the last created id?
>>>
>>>Thanks,
Chris
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform