Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2004, 01:36 PM
Registered User
 
Join Date: Jun 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trying to send SQL results to a single variable

hello folks,
 I am trying to create some code which will allow me to run a sql select command, save the results in a variable, and then use that variable to run a sql insert command.


    Dim db As Database
    Dim strSQL1 As String
    Dim strSQL2 As String
' Dim CompanyIdPlaceHolder As String
' Not sure how to use this as of yet.


    strSQL1 = "Select max(CompanyID) from Company"
'Contacts is a seperate table linked to Company by the field CompanyID
    strSQL2 = "Insert into Contacts (FirstName, LastName, CompanyID)Values " & "(" & conQuote & "No" & conQuote & ", " & conQuote & "Contact" & conQuote & ", " & **results from strSQL1** & ")"

'I am trying to get the results of the first command to be part of the sql command executed here.
db.Execute strSQL1
'db.Execute strSQL2
 
Old June 3rd, 2004, 01:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hello!!!

db.execute returns a recordset to you..

just read the data from it, then construct the second sql and execute it...

HTH

Gonzalo
 
Old June 3rd, 2004, 01:44 PM
Registered User
 
Join Date: Jun 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry if this is very basic, but that is exactly the problem that I am having. I don't know what you mean when you say db.execute returns a recordset to me and how I read the data from it.

I have been trying things such as:
CompanyIdPlaceHolder = db.Execute strSQL2

and I keep getting errors. Any additional guidance is helpful!

thanks,
 nathaniel

Quote:
quote:Originally posted by gbianchi
 hello!!!

db.execute returns a recordset to you..

just read the data from it, then construct the second sql and execute it...

HTH

Gonzalo
 
Old June 3rd, 2004, 01:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ok.. are you using dao or ado??

HTH

Gonzalo
 
Old June 3rd, 2004, 01:54 PM
Registered User
 
Join Date: Jun 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not sure actually. are there major differences between the two?


Quote:
quote:Originally posted by gbianchi
 ok.. are you using dao or ado??

HTH

Gonzalo
 
Old June 3rd, 2004, 01:58 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

in fact yes... there are to diferents way to connect to the database, and in fact dao only works with access 97, 2000 depending on the version of dao that you are using..
how did you setup your connection to the database??

you have a connection object or use opendatabase????


HTH

Gonzalo
 
Old June 3rd, 2004, 02:16 PM
Registered User
 
Join Date: Jun 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The database is all local (just tables using Access 2000) so I don't think either is in use. Sorry for the limited information; I have just taken over this database (with limited experience) from someone else and we are trying to make some updates to it.

thanks for your help.

Nathaniel

Quote:
quote:Originally posted by gbianchi
 in fact yes... there are to diferents way to connect to the database, and in fact dao only works with access 97, 2000 depending on the version of dao that you are using..
how did you setup your connection to the database??

you have a connection object or use opendatabase????


HTH

Gonzalo
 
Old June 3rd, 2004, 02:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

ahhhhhh.. are you coding inside access???

HTH

Gonzalo
 
Old June 3rd, 2004, 02:22 PM
Registered User
 
Join Date: Jun 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am coding in the VB/code portion of Access. does that help?


Quote:
quote:Originally posted by gbianchi
 ahhhhhh.. are you coding inside access???

HTH

Gonzalo
 
Old June 3rd, 2004, 02:36 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

mmm.. ok.. let's try something..

you can dim a recordset. the execute command will return you a recordset, then you can read the data from it..

sorry but i will not code it for you, i dont have a lot of experience inside access...

but look for it in the help file...

HTH

Gonzalo





Similar Threads
Thread Thread Starter Forum Replies Last Post
Put together 2 selects results in a single one romulo.petri SQL Language 3 March 6th, 2008 03:43 AM
Check two string values on a single variable?? ramesh.kumarm XSLT 2 June 29th, 2006 03:29 AM
How to send multiple columns’ data of a single row swadhinm ASP.NET 1.x and 2.0 Application Design 2 June 1st, 2005 07:59 AM
How to store single value in variable? sacred21 Classic ASP Basics 1 December 29th, 2004 05:25 AM
send variable value with (?) doosti HTML Code Clinic 1 November 10th, 2004 03:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.