473,770 Members | 7,229 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 ConnectionStrin g within my form. Therefore http://www.mikesdotnet ting.com/Article.aspx?Ar ticleID=54 was close but not exactly what I need at this point.

So far I have done the following (Without positive results):
<asp:SqlDataSou rce ID="AddProductD ataSource" runat="server"
ConnectionStrin g="Provider=Mic rosoft.Jet.OLED B.4.0;Data Source=C:\~WEBS ITES\insurance\ App_Data\Insura nce.mdb"
InsertCommand=" INSERT INTO Leads (firstname, lastname) VALUES (@firstname, @lastname); SET @ID = @@IDENTITY"
ProviderName="S ystem.Data.OleD b">

<InsertParamete rs>
<asp:ControlPar ameter ControlID="txt_ firstName" Name="firstname " PropertyName="T ext" />
<asp:ControlPar ameter ControlID="txt_ lastName" Name="lastname" PropertyName="T ext" />
<asp:Paramete r Direction="Outp ut" Name="ID" Size="100" Type="Double" />
</InsertParameter s>
</asp:SqlDataSour ce>


In addition, I have in my code behind:

Protected Sub AddProductDataS ource_Inserted( ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.SqlD ataSourceSelect ingEventArgs) Handles AddProductDataS ource.Selecting
'Read the value of the @Identity OUTPUT parameter
Dim sID
sID = e.Command.Param eters("@ID").Va lue.ToString()
'Display(New ID)
Response.Write( "ID:" + sID)
End Sub


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

Protected Sub AddProductDataS ource_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.SqlDataSourceCo mmandEventArgs) Handles AddProductDataS ource.Inserting

However now that I have the following code, I get a different error message:
Protected Sub AddProductDataS ource_Inserting (ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.SqlD ataSourceComman dEventArgs) Handles AddProductDataS ource.Inserting
Dim query As String = "SELECT @@IDENTITY"
Dim cmd As New System.Data.Ole Db.OleDbCommand (query, e.Command.Conne ction)
Dim newid As Integer = cmd.ExecuteScal ar()
Response.Write( "ID:" + newid.ToString( ))
End Sub

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


I have also changed SqlDataSourceCo mmandEventArgs for SqlDataSourceSt atusEventArgs, but still not working...

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

Protected Sub AddProductDataS ource_Inserted( ByVal sender As Object, ByVal e As SqlDataSourceSt atusEventArgs) Handles AddProductDataS ource.Inserted
Dim query As String = "SELECT @@IDENTITY"
Dim cmd As New System.Data.Ole Db.OleDbCommand (query, e.Command.Conne ction)
'Dim newid As Integer = e.Command.Param eters("@NewId") .Value
Dim newid As Integer = cmd.ExecuteScal ar()
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
2035
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 record is added. The problem is that I don't know how to do it, when I'm not using stored procedures. I found an article in which OnRowUpdated event of the dataadapter is used. On this event ExecuteScalar method of the oledbcommand object is called...
6
2380
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 SQL server... How do I return the recordID after I have added the record?
1
2774
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 record is added. The problem is that I don't know how to do it, when I'm not using stored procedures. I found an article in which OnRowUpdated event of the dataadapter is used. On this event ExecuteScalar method of the oledbcommand object is called...
1
1027
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
11284
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: <asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings: ConnectionString1 %>" SelectCommand="UserLkp" SelectCommandType="StoredProcedure"
6
2746
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 mostly handling let say 5 companies. Every time I have to navigate or choose the find record button to get the right company. I am looking fo a feature to have listed in a combo list the last 5 visited records ("recently visited records").
4
3180
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 not there, they are to click a
1
11568
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 SQLDataSource to load data from several tables into datasets or datatables, work with the data, then insert new rows into tables in the SQL Server database. I can not find any example code showing me how to do this. I don't even see any example...
5
13289
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 As New System.Data.DataView dv = SqlDataSource1.Select(sqlarg)
0
9592
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3972
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 we have to send another system
3
2817
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.