Print Page | Close Window

whats wrong with this code (scope_identity)

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=21786
Printed Date: 28 March 2026 at 7:54am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: whats wrong with this code (scope_identity)
Posted By: mike7510uk
Subject: whats wrong with this code (scope_identity)
Date Posted: 30 October 2006 at 11:56am
i want to pass the pk from table1 into table 2, i think i have the select bit right but how do i get it to insert into table 2...
 
here is my code...
 

<form id="form1" runat="server">

<div>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="tableID"

DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundField DataField="tableID" HeaderText="tableID" InsertVisible="False" ReadOnly="True"

SortExpression="tableID" />

<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />

<asp:BoundField DataField="phone" HeaderText="phone" SortExpression="phone" />

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

InsertCommand="INSERT INTO Table1 (name, phone) VALUES (@name, @phone); SELECT SCOPE_IDENTITY()"

SelectCommand="SELECT * FROM [Table1]">

<InsertParameters>

<asp:controlParameter Name="name" ControlID="name" Type="String" />

<asp:controlParameter Name="phone" ControlID="phone" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

<asp:TextBox ID="name" runat="server"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Button" />

<asp:TextBox ID="phone" runat="server"></asp




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net