I'm inserting a sort of data from a formview into the database. The primary key is set to increment automatically.
After the insertion I'm trying to get the primary key in order to use in another formview (same page) to insert data on different table.
The code:
asp:SqlDataSourceID="newSchemaSqlDataSource"runat="server"ConnectionString="<%$ ConnectionStrings:logprocConnectionString1 %>"
InsertCommand="INSERT INTO [LogSchema] ([Title], [Type], [InitPattern], [EndPattern], [SetupDate]) VALUES (@.Title, @.Type, @.InitPattern, @.EndPattern, @.SetupDate); SELECT @.NewID = SCOPE_IDENTITY()" OnInserted="newSchemaSqlDataSource_Inserted">
<InsertParameters>
<asp:ParameterName="Title"Type="String"/>
<asp:ParameterName="Type"Type="String"/>
<asp:ParameterName="InitPattern"Type="String"/>
<asp:ParameterName="EndPattern"Type="String"/>
<asp:ParameterName="SetupDate"Type="DateTime"/>
<asp:ParameterName="NewID"Type="Int32"/>
</InsertParameters>
Backend:
protectedvoid newSchemaSqlDataSource_Inserted(object sender,SqlDataSourceStatusEventArgs e){
int newid = (int)e.Command.Parameters["@.NewID"].Value;Response.Write(newid.ToString());
}
The problem is the e.Command.Parameters["@.NewID"].Value is returning NULL as I could see at the debug. What am I missing?
Try setting the Direction property of your "NewID" Parameter to "Output".
<asp:parameter direction="Output" name="NewID" type="Int32" />|||Thanks a lot... it works!!!!
No comments:
Post a Comment