Results 1 to 6 of 6
  1. #1
    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

  2. #2
    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

  3. #3
    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

  4. #4
    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 ?

  5. #5
    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

  6. #6
    Join Date
    Jan 2004
    Posts
    3

    Re: Insert Sql command in Visual Basic 6 code

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •