Tuesday, February 21, 2012

scope_identity from vwd VB

I have seen plenty of messages about using scope_index by creating parameters using HTML but I would like to do it from my .aspx.vb page.

Does anybody know if this is possible? I have got as far as the code below and get stuck when trying to add a new parameter with direction of output.

Any help would be much appreciated, cheers,

Doug.

Dim

NewPropertyAs SqlDataSource =New SqlDataSource

NewProperty.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings(

"ConnectIt").ToString()

NewProperty.InsertCommand =

"INSERT INTO Test (Name) VALUES (@.Name); SET @.NewID=SCOPE_IDENTITY()"

NewProperty.InsertParameters.Add(NewID, id)

NewProperty.Insert()

Use executescalar instead

NewProperty.InsertCommand ="INSERT INTO Test (Name) VALUES (@.Name); SELECT SCOPE_IDENTITY()"

Response.Write(NewProperty.ExecuteScalar.ToString())

HTH
Regards

|||

Thanks for the rapid response but I get the following error when I try it:

'ExecuteScalar' is not a member of the system.web.UI.WebControls.SqlDataSource

Any idea how I overcome this?

Thanks again,

Doug.

|||

Opps, i'm sorry

I thought you are talking about sqlcommand.

Check the following MSDN

http://msdn2.microsoft.com/en-us/system.web.ui.webcontrols.sqldatasource.inserted.aspx

Regards

No comments:

Post a Comment