473,508 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

@@IDENTITY of recently added record using SqlDataSource | MS Acccess ASP.NET VB

2 New Member
Hello Everybody,
I am Using @@IDENTITY from MS Access (YES-It is possible) using SqlDataSource -NO STORE PROC- in ASP.NET {VB CODE} to retrieve the ID of a inserted record.

Please keep in mind I am using a form page an code behing, and I have currently my ConnectionString within my form. Therefore http://www.mikesdotnetting.com/Article.aspx?ArticleID=54 was close but not exactly what I need at this point.

So far I have done the following (Without positive results):
<asp:SqlDataSource ID="AddProductDataSource" runat="server"
ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=C:\~WEBSITES\insurance\App_Data\Insurance.m db"
InsertCommand="INSERT INTO Leads (firstname, lastname) VALUES (@firstname, @lastname); SET @ID = @@IDENTITY"
ProviderName="System.Data.OleDb">

<InsertParameters>
<asp:ControlParameter ControlID="txt_firstName" Name="firstname" PropertyName="Text" />
<asp:ControlParameter ControlID="txt_lastName" Name="lastname" PropertyName="Text" />
<asp:Parameter Direction="Output" Name="ID" Size="100" Type="Double" />
</InsertParameters>
</asp:SqlDataSource>


In addition, I have in my code behind:

Protected Sub AddProductDataSource_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEv entArgs) Handles AddProductDataSource.Selecting
'Read the value of the @Identity OUTPUT parameter
Dim sID
sID = e.Command.Parameters("@ID").Value.ToString()
'Display(New ID)
Response.Write("ID:" + sID)
End Sub


After some suggestions I changed my code a little as follows:

Protected Sub AddProductDataSource_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles AddProductDataSource.Inserting

However now that I have the following code, I get a different error message:
Protected Sub AddProductDataSource_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEven tArgs) Handles AddProductDataSource.Inserting
Dim query As String = "SELECT @@IDENTITY"
Dim cmd As New System.Data.OleDb.OleDbCommand(query, e.Command.Connection)
Dim newid As Integer = cmd.ExecuteScalar()
Response.Write("ID:" + newid.ToString())
End Sub

But I get an error message in line
Dim newid As Integer = cmd.ExecuteScalar()


I have also changed SqlDataSourceCommandEventArgs for SqlDataSourceStatusEventArgs, but still not working...

Thanks in advance for your suggestions.
PD
Jul 31 '08 #1
1 3066
Pipo Dyer
2 New Member
Found the answer:

Protected Sub AddProductDataSource_Inserted(ByVal sender As Object, ByVal e As SqlDataSourceStatusEventArgs) Handles AddProductDataSource.Inserted
Dim query As String = "SELECT @@IDENTITY"
Dim cmd As New System.Data.OleDb.OleDbCommand(query, e.Command.Connection)
'Dim newid As Integer = e.Command.Parameters("@NewId").Value
Dim newid As Integer = cmd.ExecuteScalar()
Response.Write("ID:" + newid.ToString())
End Sub
Jul 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2004
by: Taras | last post by:
Hello! I have a problem. I'm using a dataset in VB.NET with multiple tables with relations between them. I would like dataset to update to all related tables with right identity, when certain...
6
2359
by: Tony Stoker | last post by:
I have a .Net web app that adds a record to a SQL database. After the user adds their record I want to have a link that will link them to their new record! The recordID is a AutoNumber in the...
1
2765
by: Taras | last post by:
Hello! I have a problem. I'm using a dataset in VB.NET with multiple tables with relations between them. I would like dataset to update to all related tables with right identity, when certain...
1
1013
by: C CORDON | last post by:
How can I get the ID (in a autonumber field) for the last added record in access? TIA!
3
11270
by: michelle | last post by:
I am trying to get an output value from a stored procedure using sqlDataSource in asp.net 2.0. But I only get a null value for the output. Can someone please help? The sqlDataSource: ...
6
2729
by: AA Arens | last post by:
Hi, I have a database with 2 main forms. Contacts and companies. I share the base with two others via LAN. On the companies form I have buttons to navigate throught the records (>400). We are...
4
3141
by: piscogirl | last post by:
Hi all, Here's my case: I have a form: Event Form and a subform: AttendanceSubForm The user selects a name (from a Person Table) on the subform to register for the event. If the name is...
1
11550
by: tom c | last post by:
I am using Visual Web Developer 2005 Express Edition. I created a SQLDataSource just by draging the control to the form and filling in the blanks in the wizard. In code I need to use the...
5
13272
by: Luqman | last post by:
I added new rows to the GridView with the following code. I am using SqlDataSource and Sql Server 2000 Northwind Database Customers table. Dim sqlarg As New DataSourceSelectArguments Dim dv...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3195
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.