PDA

Click to See Complete Forum and Search --> : ADO and adding fields. or something...


Sep 9th, 2000, 08:13 PM
How do I use ADO to add values to a DB??
if I had a field called

PageID
and a field called
Content

How would I add "Hello" to the PageID, and "hehehe" to the content field?

I am not using the control, I am using a reference to ADO 2.5

jason1972
Sep 10th, 2000, 04:34 AM
Assuming you have an Access 97 database 'C:\MyDB.mdb',
and that database has a table named 'MyTable' with the
fields 'PageID' and 'Content', this is one way to do it:

Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim strConnect As String
Dim strQuery As String

Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command

'Create the connection string.
strConnect = "Provider=Microsoft.Jet.OLEDB.3.51;" & _
"Persist Security Info=False;Data Source=C:\MyDB.mdb"

'Open a connection to the database.
cnn.Open strConnect

'Create the query string.
strQuery = "insert into MyTable (PageID, Content) " & _
"values ('Hello', 'hehehe')"

'Create the insert query.
Set cmd.ActiveConnection = cnn
cmd.CommandType = adCmdText
cmd.CommandText = strQuery

'Execute the insert query.
cmd.Execute

'Close the connection to the database.
cnn.Close

Sep 10th, 2000, 11:03 AM
Ok, Thanks very much,
I forget all about using SQL....

Thanks.