aninec
asked on
ASP.NET Scope Identity
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.