| | |
<Help!!> I need to retrieve an autonumber from microsoft access using visual C#
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
I am working on my senior project and I am using C#.net and Microsoft Access to create a program that lets the user store information into a database. I have many tables but the primary table that mostly everything connects to is the customers table. Well I know how to insert, update and delete using C#. But I need to know how to retrieve the primary key from the customers table which happens to be an autonumber. I kind of understand that I need to use SCOPE_IDENTITY or @@IDENTITY. I just have no idea how. I have tried a couple ways without any success.
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
Re: <Help!!> I need to retrieve an autonumber from microsoft access using visual C#
0
#2 Apr 24th, 2008
Do your Insert Query, the do a SELECT @@IDENTITY Query immediately afterward. It's best to do both in a stored procedure with the Identity as an OUT parameter.
Try this link: http://www.netomatix.com/adonetauto.aspx
Try this link: http://www.netomatix.com/adonetauto.aspx
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
Re: <Help!!> I need to retrieve an autonumber from microsoft access using visual C#
0
#3 Apr 24th, 2008
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
Re: <Help!!> I need to retrieve an autonumber from microsoft access using visual C#
0
#4 Apr 24th, 2008
•
•
Join Date: Apr 2008
Posts: 45
Reputation:
Solved Threads: 10
Re: <Help!!> I need to retrieve an autonumber from microsoft access using visual C#
0
#5 Apr 25th, 2008
•
•
Join Date: Apr 2008
Posts: 1
Reputation:
Solved Threads: 1
Re: <Help!!> I need to retrieve an autonumber from microsoft access using visual C#
0
#6 Apr 25th, 2008
Hi
If your DB going to be affected by several procedures or triggers at the same time into your session, you have to use SCOPE_IDENTITY().
Example:
CREATE PROCEDURE prTable_Insert
@value1 varchar(16)
AS
INSERT INTO Table(field1) VALUES (@value1)
SELECT SCOPE_IDENTITY()
GO
This going to return the last value inserted by this store procedure, but if you use @@IDENTITY this going to return the last ID inserted in your sesion, and this value could be another inserted by another process or trigger out of this procedure executed in your actual session.
Good luck!!!
If your DB going to be affected by several procedures or triggers at the same time into your session, you have to use SCOPE_IDENTITY().
Example:
CREATE PROCEDURE prTable_Insert
@value1 varchar(16)
AS
INSERT INTO Table(field1) VALUES (@value1)
SELECT SCOPE_IDENTITY()
GO
This going to return the last value inserted by this store procedure, but if you use @@IDENTITY this going to return the last ID inserted in your sesion, and this value could be another inserted by another process or trigger out of this procedure executed in your actual session.
Good luck!!!
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
Re: <Help!!> I need to retrieve an autonumber from microsoft access using visual C#
0
#7 Apr 25th, 2008
![]() |
Other Threads in the C# Forum
- Previous Thread: how to add database into the while iam deploying.
- Next Thread: Changing from Delphi to C#
| Thread Tools | Search this Thread |
.net access algorithm alignment app array barchart bitmap box broadcast c# c#gridviewcolumn cast check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datatable datetime degrees development draganddrop drawing elevated encryption enum excel file focus form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml






