If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Insert Sql command in Visual Basic 6 code

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jan 2004
Location: Palermo - Italia
Posts: 4
Question Insert Sql command in Visual Basic 6 code

Hi all, i have a little problem. I would like to insert an sql command (like a select for example) in the code of a vb6 program just to make the result set visible in a text box, for example. After I declare a variable as string in which I put my sql-command-string, what have I to do to execute it?

tnx for your help.

glass
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Nov 2003
Posts: 76
strsql="INSERT INTO Tablename (fieldname1,fldname2) Values (val1,val2)"

create a connection to the db(cnn1) using adodb.connection.
cnn1.execute(strsql)


HTH
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Jan 2004
Location: Palermo - Italia
Posts: 4
Unhappy

tnx for your answer, but...it doesn't accept the "adodb.connection" command (I don't know why), so I used the

dim connection as new dbengine

row of code but i don't know how to use it.

i'm going to try in another way, with another command.
i only have to know which command!!!!
glass
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Feb 2002
Posts: 2,232
That is because you have to set a reference in your project to ms ado 2.X. What is your database you are connecting to - access ?
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Jan 2004
Location: Palermo - Italia
Posts: 4
Angry

yes, it is an access 97 database of 20 MB. i can use the properties of the objects (such as text box) just to take data from the db, with datasource and data field command after created the data object in the form and setted the database name in its property. but i would like to filter the data incoming from the tables using an sql command like "select column from table where condition" and insert it in a text box. how can i do?

tnx for your help
glass
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Jan 2004
Posts: 3
Re: Insert Sql command in Visual Basic 6 code

Quote:
Originally posted by glassonline78
Hi all, i have a little problem. I would like to insert an sql command (like a select for example) in the code of a vb6 program just to make the result set visible in a text box, for example. After I declare a variable as string in which I put my sql-command-string, what have I to do to execute it?

tnx for your help.

glass
i assume u have one text box and one command button on ur form. make sure u have an odbc connection which is ur dsn. the databse i am using here is oracle with front end vb.

in the general declarations:
dim db as database
dim rs as recordset

in the form load:
Set db = OpenDatabase("aaa", False, false, "odbc;uid=scott;pwd=tiger;dsn=aaa")
Set rs = db.OpenRecordset("select * from customers")
text1.text=rs!password

on the command click:
rs.movenext
movefields
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On