SQLDataSource and Identity column

  • Thread starter Thread starter Vik
  • Start date Start date
V

Vik

How can I retrieve an Identity value after inserting a new row with an
SQLDataSource?

Thanks.

Victor
 
End your InsertCommand with ";set @NewId = scope_identity()".

Handle the SqldataSource Inserted event like this:

protected void myDataSource_Inserted(object sender,
SqlDataSourceStatusEventArgs e)
{
// get Id of the new record
this.newId = Convert.ToInt32(e.Command.Parameters["@NewId"].Value);
}


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Vik said:
How can I retrieve an Identity value after inserting a new row with an
SQLDataSource?

Thanks.

Victor



__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4068 (20090512) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4068 (20090512) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
I stumbled on this while trying to answer the same sort of question. I just
wanted to add, for anyone else who stumbles on this as well, that I also had
to make the markup in the InsertParameters look like this:

<asp:Parameter Name="NewEventID" Type="Int32" Direction="Output"/>

Only the intial Parameter Name attribute was included by default.

type="Int32

Eliyahu Goldin said:
End your InsertCommand with ";set @NewId = scope_identity()".

Handle the SqldataSource Inserted event like this:

protected void myDataSource_Inserted(object sender,
SqlDataSourceStatusEventArgs e)
{
// get Id of the new record
this.newId = Convert.ToInt32(e.Command.Parameters["@NewId"].Value);
}


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Vik said:
How can I retrieve an Identity value after inserting a new row with an
SQLDataSource?

Thanks.

Victor



__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4068 (20090512) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4068 (20090512) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
I stumbled on this while trying to answer the same sort of question. I just
wanted to add, for anyone else who stumbles on this as well, that I also had
to make the markup in the InsertParameters look like this:

<asp:Parameter Name="NewEventID" Type="Int32" Direction="Output"/>

Only the intial Parameter Name attribute was included by default.

type="Int32

Eliyahu Goldin said:
End your InsertCommand with ";set @NewId = scope_identity()".

Handle the SqldataSource Inserted event like this:

protected void myDataSource_Inserted(object sender,
SqlDataSourceStatusEventArgs e)
{
// get Id of the new record
this.newId = Convert.ToInt32(e.Command.Parameters["@NewId"].Value);
}


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


Vik said:
How can I retrieve an Identity value after inserting a new row with an
SQLDataSource?

Thanks.

Victor



__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4068 (20090512) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


__________ Information from ESET NOD32 Antivirus, version of virus signature database 4068 (20090512) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
Back
Top