473,513 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Insert into Query

1 New Member
Hi,

Im using a querydef object for inserting into a table. But in that table there is a automated genereated primary key. How can I get that key once the recored successfully inserted into the table?

Here is my code:

Dim qry As QueryDef
str = "INSERT INTO Vendor (vendor) VALUES ('" & VendorList.Value & "')"
qry.SQL str
qry.Execute

So in the vendor table there is a column "vendorID", which is a automated generated key. How can i get that after the above code? Any help or guidence will be greatly appreciated.

regards,
Umer
Jul 2 '07 #1
1 1059
danp129
323 Recognized Expert Contributor
Hi,

Im using a querydef object for inserting into a table. But in that table there is a automated genereated primary key. How can I get that key once the recored successfully inserted into the table?

Here is my code:

Dim qry As QueryDef
str = "INSERT INTO Vendor (vendor) VALUES ('" & VendorList.Value & "')"
qry.SQL str
qry.Execute

So in the vendor table there is a column "vendorID", which is a automated generated key. How can i get that after the above code? Any help or guidence will be greatly appreciated.

regards,
Umer
If it's Ms SQL Server you could use something like this:

Expand|Select|Wrap|Line Numbers
  1. Dim vendorID
  2. rs.Open "SELECT @@IDENTITY AS id", adoCon
  3. vendorID=rs("id")
  4. rs.Close
Dunno about other databases.
Jul 2 '07 #2

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

Similar topics

10
2584
by: johnnyboy10017 | last post by:
I am having a hell of a time with what I think is a very simple query: It won't actually insert a new record into the specified table, but returns no error, in fact it returns "1" (or true) that...
5
2714
by: Juho Saarikko | last post by:
I made a Python script which takes Usenet message bodies from a database, decodes uuencoded contents and inserts them as Large Object into a PostGreSQL database. However, it appears that the to...
3
4500
by: jain-neeraj | last post by:
Hi, We have a problem in our mobile calls billing software. To solve it, I need an outer join in a complicated query. Following are the simplified tables with sample data: create table...
2
2856
by: Gunnar Vøyenli | last post by:
Hi Some days ago I posted a problem with a query. Thaks to Dave and John, I got a little closer to a solution. Their suggestion was a solution to my problem as I stated it, but the real problem...
2
1900
by: avinash | last post by:
hello myself avinash i am developing on application having vb 6 as front end and sql server 7 as back end. when i use insert query to insert data in table then the date value of that query is...
5
5447
by: Ritesh | last post by:
Hi All, According to my observation using SP_WHO2 in my database, some INSERT statements are getting blocked by SELECT statements. Though the blocking SELECT statement is having ReadPast hint,...
3
1728
by: Myron | last post by:
I'm trying to create a query that will tell me which requests took longer than 10 days to move one from particular state to another state. The query I've created returns the correct requests, but...
4
2729
by: Bradley Burton | last post by:
I'm using Allen Brown's code for audit logging (http://allenbrowne.com/AppAudit.html), but I'm having a problem. My aud table doesn't populate with the tracking info at all. I think it might be a...
3
2550
by: os2 | last post by:
hi i have an insertion problem with my rtu table datatype for date1 field is: datetime i try to insert local date to the database (mysql) source code struct tm *date;
1
1152
by: Net Virtual Mailing Lists | last post by:
Hello, I have 3 tables which are joined that I need to create a summation for and I just cannot get this to work. Here's an example: CREATE table1 ( id1 INTEGER, title1 VARCHAR
0
7264
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
7166
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
7543
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
7106
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...
1
5094
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
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
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
805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
459
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.