473,387 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

simple way to insert new ms access record and return autoid value

Hello,

i am wondering if there is a simple way to insert a new record into an MS
Access db and read out the newly created auto-ID field. Using ASP this was
rather simple, but in ASP.NET (VB) it seems to have become rather
complex????

cheers, Olaf
Nov 19 '05 #1
4 1927
See the following KB article:
HOW TO: Retrieve the Identity Value While Inserting Records into
Access Database By Using Visual Basic .NET
http://support.microsoft.com/default...b;en-us;815629

--Mary

On Mon, 21 Feb 2005 18:14:47 +0100, "olafmol" <ol**@expansions.nl>
wrote:
Hello,

i am wondering if there is a simple way to insert a new record into an MS
Access db and read out the newly created auto-ID field. Using ASP this was
rather simple, but in ASP.NET (VB) it seems to have become rather
complex????

cheers, Olaf


Nov 19 '05 #2
Hi Olaf,

To insert a record

In ADO:
Dim conn As New ADODB.Connection
conn.Open connextString
conn.Execute insertSql
conn.Close
Set conn = Nothing

In ADO.NET
Dim conn As New OleDbConnection(connectionString)
conn.Open()
Dim command As OleDbCommand = conn.CreateCommand()
command.CommandType = CommandType.Text
command.CommandText = insertSql
command.ExecuteNonQuery()
conn.Close()

So what's big difference?

HTH

Elton Wang
el********@hotmail.com

-----Original Message-----
Hello,

i am wondering if there is a simple way to insert a new record into an MSAccess db and read out the newly created auto-ID field. Using ASP this wasrather simple, but in ASP.NET (VB) it seems to have become rathercomplex????

cheers, Olaf
.

Nov 19 '05 #3
Hello Elton,

not much, but where do you read the autonumber value of the newly inserted
record?

cheers, Olaf

Elton Wang <an*******@discussions.microsoft.com> wrote in message
news:0a****************************@phx.gbl...
Hi Olaf,

To insert a record

In ADO:
Dim conn As New ADODB.Connection
conn.Open connextString
conn.Execute insertSql
conn.Close
Set conn = Nothing

In ADO.NET
Dim conn As New OleDbConnection(connectionString)
conn.Open()
Dim command As OleDbCommand = conn.CreateCommand()
command.CommandType = CommandType.Text
command.CommandText = insertSql
command.ExecuteNonQuery()
conn.Close()

So what's big difference?

HTH

Elton Wang
el********@hotmail.com

-----Original Message-----
Hello,

i am wondering if there is a simple way to insert a new

record into an MS
Access db and read out the newly created auto-ID field.

Using ASP this was
rather simple, but in ASP.NET (VB) it seems to have

become rather
complex????

cheers, Olaf
.

Nov 19 '05 #4
You can try

After
command.ExecuteNonQuery()

command.CommandText = "SELECT @@IDENTITY"
Dim obj As Object
Dim autoNum As Integer
obj = command.ExecuteScalar()
If not obj Is Nothing Then
autoNum = Integer.Parse(obj)
End If
HTH

Elton
-----Original Message-----
Hello Elton,

not much, but where do you read the autonumber value of the newly insertedrecord?

cheers, Olaf

Elton Wang <an*******@discussions.microsoft.com> wrote in messagenews:0a****************************@phx.gbl...
Hi Olaf,

To insert a record

In ADO:
Dim conn As New ADODB.Connection
conn.Open connextString
conn.Execute insertSql
conn.Close
Set conn = Nothing

In ADO.NET
Dim conn As New OleDbConnection(connectionString)
conn.Open()
Dim command As OleDbCommand = conn.CreateCommand()
command.CommandType = CommandType.Text
command.CommandText = insertSql
command.ExecuteNonQuery()
conn.Close()

So what's big difference?

HTH

Elton Wang
el********@hotmail.com

>-----Original Message-----
>Hello,
>
>i am wondering if there is a simple way to insert a new

record into an MS
>Access db and read out the newly created auto-ID field.

Using ASP this was
>rather simple, but in ASP.NET (VB) it seems to have

become rather
>complex????
>
>cheers, Olaf
>
>
>.
>

.

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: olafmol | last post by:
Hello, i am wondering if there is a simple way to insert a new record into an MS Access db and read out the newly created auto-ID field. Using ASP this was rather simple, but in ASP.NET (VB) it...
9
by: Pete | last post by:
Does anyone have a simple html vbscript or other type of snippet they can share that appends a record to a access database via ADO or DAO? I would like to allow users that don't have Microsoft...
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
6
by: HS1 | last post by:
Hello I have a table in Access Database. This table has a AutoNumber field. I use a DataGrid to show that table When I insert a new record in for this table using a DataGrid, there is a...
2
by: Deano | last post by:
Problem is that there are lots and lots of fields in an employee record. I specify a form control as the criterion for one of those fields which is the value of the primary key for that record. ...
7
by: Materialised | last post by:
Hi Folks, Just a quickie, I am inserting some records (individually) into a SQL Server Table. I am wondering how can I detect primary key violations on this data which I am inserting into the...
4
by: Mark Olbert | last post by:
I am struggling with trying to retrieve the value of an autoincrement identity field after a DetailsView Insert operation. The DetailsView is bound to an SqlDataSource control. So far as I can...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...

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.