Results 1 to 9 of 9

Thread: simple db question

  1. #1

    Thread Starter
    Member visual poet's Avatar
    Join Date
    Apr 2002
    Location
    In the driver seat of my Firebird...
    Posts
    52

    Unhappy simple db question

    How do I run an insert query against a db using the Ado Data Control, assuming I have the adodc already connected to the db I want to use?

    Can you show me the code...

    Thank you very much

    -----------------




    To steal ideas from one person is plagiarism;
    to steal from many is research.

    Visual Poet :^)

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    If you are already connected then to insert a new record first use Recordset.AddNew, enter the values you require then update the recordset using Recordset.Update.

    HTH

    DJ

  3. #3

    Thread Starter
    Member visual poet's Avatar
    Join Date
    Apr 2002
    Location
    In the driver seat of my Firebird...
    Posts
    52
    Sorry I meant that I already have a SQL expression that would do some moving of data from one table to another - insert then delete - so the expression is ready and all I need is to execute it as a query... how can I do that?

    Thanks a lot for your help and sorry for not explaining myself so well....

    VP

    -----------------




    To steal ideas from one person is plagiarism;
    to steal from many is research.

    Visual Poet :^)

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131
    Could you post the code you have so far to connect to the database.

  5. #5

    Thread Starter
    Member visual poet's Avatar
    Join Date
    Apr 2002
    Location
    In the driver seat of my Firebird...
    Posts
    52

    Here's My CODE

    I am not sure where to put the query I want to run, so I put it in the recordsource property of the adodc...... but I bet that's not the place to put it... all I need is to run this sql statement againt the db without returning any results.... thx

    Code:
    Private Sub cmdGo_Click()
            
            On Error GoTo Err
                            
            adoReport.CommandType = adCmdText + adExecuteNoRecords
            adoReport.RecordSource = "INSERT INTO SongRequestBak SELECT * From songrequest WHERE (WellReceived = 1)AND (ID < (SELECT MAX(id) FROM songrequest))DELETE FROM songrequest WHERE (WellReceived = 1)AND (ID < (SELECT MAX(id) FROM songrequest))"
                    
            Exit Sub
    Err:
        MsgBox Err.Description, vbOKOnly, "Error"
        Screen.MousePointer = vbDefault
    End Sub

    -----------------




    To steal ideas from one person is plagiarism;
    to steal from many is research.

    Visual Poet :^)

  6. #6
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    Try:
    VB Code:
    1. adoReport.Database.Execute (""INSERT INTO SongRequestBak SELECT * From songrequest WHERE (WellReceived = 1)AND (ID < (SELECT MAX(id) FROM songrequest))DELETE FROM songrequest WHERE (WellReceived = 1)AND (ID < (SELECT MAX(id) FROM songrequest))")

  7. #7

    Thread Starter
    Member visual poet's Avatar
    Join Date
    Apr 2002
    Location
    In the driver seat of my Firebird...
    Posts
    52
    I am so glad that we too think alike, but this method doesnt' exist.....!!

    adodc.database <---- doesn't exist

    adodc.recordset <---- exists but without the execute method

    anyway out?

    Thx a lot, I thought this was an easy problem, but I didn't know it would take so much thinking.....

    VP

    -----------------




    To steal ideas from one person is plagiarism;
    to steal from many is research.

    Visual Poet :^)

  8. #8
    Fanatic Member
    Join Date
    Aug 2001
    Location
    Connecticut
    Posts
    855
    execute is a connection object method. So you can try :
    set cn = adodc1.Recordset.ActiveConnection
    cn.Execute sqlstring
    VB 6.0, Access, Sql server, Asp

  9. #9
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    If you have it, you would be better off referencing Microsoft Access 8.0 Data Object Library. Then you will have the methods you need.

Posting Permissions

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



Click Here to Expand Forum to Full Width