Hi,
Thanks for replying but I have no spaces in my parameter name.
I have also found a way for it to work but it seems rather "round
about".
In the SQL I return the @@IDENTITY but by default the ID is not a
parameter and when I add it to the parameters collection it keeps
disapearing! I think it does this whenever I go into the SQL or the
parameters collection.
Also this way I have to pass each parameter to the SQL which means that
I have to get each item from the Grid. This is also painfull.
Is this the correct way to do this or is there an easier way that I am
missing????
You don't need to return the auto-key with a parameter, you can return a
single row resultset with the new key:
INSERT INTO table1( field1, field2 ) VALUE ( @field1, @field2 );
SELECT keyfield, field1, field2 FROM table1 WHERE keyfield =
SCOPE_IDENTITY();
With an insert query like that, once you perform a TableAdapter (or
DataAdapter) update it will replace the temporary keys with the new ones
(from db) in the DataSet/DataTable.
If you happen to use a TableAdapter, then you should be able to
configure it so that i will generate an insert command like the above.
Inside DataSet schema designer, click on the TableAdapter to select it,
then right click on your TableAdapter and choose configure. Then click
on "Advanced Options..." and check "Refresh the data table".
HTH,
Greetings
Phil
Hi Phill,
I'm very far to be an expert in this stuff, but I think you cannot
have
a variavel (parameter name) with spaces, I mean you have "@Parent
Alias"
in the insert statement, try "@Parent_Alias" or "@ParentAlias" or
whatever and compile it.
Rgds,
Tiago Teixeira
-----Original Message-----
From: Phil Williams [mailto
[email protected]]
Posted At: terça-feira, 24 de Janeiro de 2006 21:46
Posted To: microsoft.public.dotnet.framework.adonet
Conversation: VB.NET - How do I return an AutoNumber from an Insert
Statement using the DataGridView
Subject: VB.NET - How do I return an AutoNumber from an Insert
Statement
using the DataGridView
Hello,
I have a Grid in a VB.Net application which I want to return the
Primary
Key
which is an AutoNumber after I insert a record. The Primary Key Number
that
I get back is not from SQL Express but from VB and it can be wrong.
I have a DataGridView that is bound to my table through my
TableAdapter.
If I go to Insert a row and then cancel it ups the autonumber that I
see in
VB. Then if Insert a row and save it, the records AutoNumber is not
the
same
as the SQL AutoNumber.
I have been trying to return the ID from SQL using @@IDENTITY but with
no
success.
Any pointers would be much appreciated.
Phil