Solved

ASP.NET Scope Identity

Posted on 2008-10-30
1
192 Views
Last Modified: 2010-04-14
I need to get the PK associated with the Insert.  Could someone look at the code and tell me where I do this.  I want to use it when I send a confirmation to the user in my Submit Sub
Protected Sub btnSubmit_Click(ByVal sender as Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
          'Will be used for multiple types of inserts - based on report event type
          If Event = "Fall" 
          sqlFallInsert.Insert()
          End If
 
       Dim mail as New MailMessage()
       mail.From=New MailAddress("Barta.Joan@mayo.edu")    
       mail.To.Add("Christensen.Katherine@mayo.edu")
             
       mail.subject="Safety Report Notification"
       mail.body = "Please do not reply to this email directly. If you have any questions, please contact Joan Barta, Safety Coordinator Email: barta.joan@mayo.edu Phone: (507) 385-5890 "
       
       Dim smpt As New SmtpClient
          smpt.Send(mail) 
         
End Sub
 
Protected Sub sqlFallInsert_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SQLDataSourceCommandEventArgs) Handles sqlFallInsert.Inserting
        	Dim Reportid As String
        	e.Command.Parameters("@PtAcct").Value = PtAcct.Text
       	e.Command.Parameters("@PtName").Value = PtName.Text
         	e.Command.Parameters("@PtStat").Value = PtStat.Text
        	e.Command.Parameters("@PtLoc").Value = PtLoc.Text
        	e.Command.Parameters("@drpdwnEvent").Value = drpdwnEvent.SelectedItem.Value 
         e.Command.Parameters("@drpdwnFacility").Value = drpdwnFacility.SelectedItem.Value 
           e.Command.Parameters("@drpdwnLocation").Value = drpdwnLocation.SelectedItem.Value 
			e.Command.Parameters("@drpdwnDept").Value = drpdwnDept.SelectedItem.Value 
 
   End Sub  
 
The Button with the DataSource
<asp:Button runat="server" Text="Submit Report" id="btnSubmit" Width="121px" Height="41px" />
	</div>
	<asp:SqlDataSource runat="server" id="SqlInsert" InsertCommand="INSERT INTO [IncidentTmp] ([PtAcct], [PtName], [PtStat], [PtLoc], [Event], [Facility], [EventLoc], [EventDept]) VALUES (@PtAcct, @PtName, @PtStat, @PtLoc, @drpdwnEvent, @drpdwnFacility, @drpdwnLocation, @drpdwnDept)"  ConnectionString="<%$ ConnectionStrings:QIMConnectionString %>" SelectCommand="SELECT [ID], [PtAcct], [PtName], [PtDob], [PtDos], [PtStat], [PtLoc] FROM [IncidentTmp]">
		
		<InsertParameters>
			<asp:parameter Name="PtAcct" Type="String" />
			<asp:parameter Name="PtName" Type="String" />
			<asp:parameter Name="PtStat" Type="String" />
			<asp:parameter Name="PtLoc" Type="String" />
			<asp:parameter Name="drpdwnEvent" Type="String"/>
			<asp:parameter Name="drpdwnFacility" Type="String"/>
			<asp:parameter Name="drpdwnLocation" Type="String"/>
			<asp:parameter Name="drpdwnDept" Type="String"/>
		</InsertParameters>
	</asp:SqlDataSource>

Open in new window

0
Comment
Question by:aninec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 20

Accepted Solution

by:
brwwiggins earned 500 total points
ID: 22841590
i've never done it using a sqldatasource but I found this article that might help
http://forums.asp.net/p/1308155/2571348.aspx

I know you can do it using ADO similar to this method http://aspalliance.com/892_CodeSnip_How_to_Get_Id_of_the_Record_Using_ASPNET_and_SQL_Server_2000.1
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question