Click to See Complete Forum and Search --> : ADO and adding fields. or something...
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
Ok, Thanks very much,
I forget all about using SQL....
Thanks.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.