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
Printable View
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
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
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
Could you post the code you have so far to connect to the database.
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
Try:VB Code:
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))")
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
execute is a connection object method. So you can try :
set cn = adodc1.Recordset.ActiveConnection
cn.Execute sqlstring
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.