Click to See Complete Forum and Search --> : ADO & SQL SERVER


Alexandra I
July 19th, 2000, 04:03 AM
Can anyone help me how to connect to SQL Server database using ADO recordset in VB? can you enlighten my mind about ODBC and DSN? I would appreciate a sample code. TY

July 21st, 2000, 03:52 AM
you will connect to a database using the Conection object.
using its Execute command you can get the Recordset
here is a VB code which might help you

Set dbConn = CreateObject("ADODB.Connection")
dbConn.Open dsnValue
Set rs = dbConn.Execute(sqlString)
if(rs.EOF = False) then
rs.MoveFirst
do while not rs.EOF
' do whatever you want with the recordset object rs
' you can access the fields on current record by rs("fieldName")

' move to next record
rs.MoveNext
loop
end if
rs.Close
dbConn.Close

sqlString can be any valid SELECT SQL statement.
you can use the other SQL statements (INSERT, UPDATE, DELETE etc) in the same way but in this case , as no recordset will be returned, you will use :

dbConn.Execute("UPDATE ...")

Good luck

Alexandra I
July 21st, 2000, 03:26 PM
Thank you very much.