i have decided (finaly) 2 go with ado instead of dao (which i have been using 4 ages).. so could someone give me the easyest possible way 2 get and set a record in a database with ado??
thnx
Printable View
i have decided (finaly) 2 go with ado instead of dao (which i have been using 4 ages).. so could someone give me the easyest possible way 2 get and set a record in a database with ado??
thnx
You would get more answers if you ask this question in "Database Development" forum but you can try an introductory tutorial for ADO by Beacon here:
http://www.vbforums.com/showthread.php?threadid=153935
Try something like this.. Its as easy as it was before with DAO.
VB Code:
Dim conn As New ADODB.Connection Dim sql As String sql = "INSERT INTO TableName(ColumnName1, ColumnName2) VALUES(value1, value2)" conn.ConnectionString = "SomeDSNName" conn.Execute sql
ADO is "almost" exactly like DAO... You should have no major progrems getting used to it.
Check out some of there.. They should help.
http://www.w3schools.com/ado/default.asp
Dim con as New ADODB.Connection
Dim Rs as New ADODB.REcordset
Con.Open ConString
Rs.Open SQLString
All done:D
Ofcourse you have to make sure your ConString And SQLString Variables actually hold a valid Connection string and SQLQuery
Arc,
Actually your going to need a bit more than that.
Rs con, SQLString
Rs needs to know what connection to use.
Also you dont need to use a recordset object just to execute a SQL statement. I dont need to be soo picky though ;)
Select reference Microsoft ADO 2.0 Library
Dim con as Connection
Dim rs as recordset
Set con=new Connection
Set rs=new Recordset
With con
.ConnectionString "User id=whatever is the user;pwd=what eve rpassword;data source=where the database is(machine name);Initial catalog=the name of the database
.Provider="the provider name" For eg: for SQL SQLOLEDB
.Open
End With
rs.open "the query statement",con
Nice work abdul!
To the others the reason there's a tutorial is so you dont have to explain it all. :)
joan you are right about the con object having to be specified, I forgot to add that on, however you put it in the wrong place. It comes after the SQLString. Rs SQLString, con. You are also correct about not having to use the Recordset Object to execute an SQL Statement, that's just my preference.Quote:
Originally posted by joan_fl
Arc,
Actually your going to need a bit more than that.
Rs con, SQLString
Rs needs to know what connection to use.
Also you dont need to use a recordset object just to execute a SQL statement. I dont need to be soo picky though ;)
I Do have to ask you one question though. You Specified your connection String as a DSN. Do businesess really use DSN connections? I mean since it uses an ODBC driver instead of OLE DB i assumed it would not be used any more.
DSNs are still used out there... there soo many older programs out there. Though your right.. I would think any new development would use a dsnLESS connection though with OLEDB.Quote:
I Do have to ask you one question though. You Specified your connection String as a DSN. Do businesess really use DSN connections? I mean since it uses an ODBC driver instead of OLE DB i assumed it would not be used any more.