Database Programming

Dim cn,rs
Set cn=CreateObject("ADODB.Connection")
Set rs=CreateObject("ADODB.RecordSet")
cn.Open "Provider=SQLOLEDB;server=class301;database=employee;trusted_connection=yes"
rs.Open "select * from emp",cn
While rs.EOF<>True
print rs("eno")&" "&rs("ename")&" "&rs("sal")&" "&rs("depcode")
rs.MoveNext
Wend
rs.Close
cn.Close
==================================
'Connection syntax for different databases
'cn.Open "Provider=ORADB;server=servername;userid=xxxx;pwd=xxxx"
'cn.Open "Provider=SQLOLEDB;server=class301;database=employee;uid=xxxxx;pwd=xxxx"
'cn.Open "Provider=Microsoft.jet.oledb.4.0; data source=e:\employee.mdb"
==================================================
Dim cn,rs
Set cn=CreateObject("ADODB.Connection")
Set rs=CreateObject("ADODB.Recordset")
cn.Open "DSN=d1"
rs.Open "select eno,ename from emp",cn
While rs.EOF<>True
print rs("eno")&" "&rs("ename")
rs.MoveNext
Wend
rs.Close
cn.Close
===========================================
Dim cn,rs
Set cn=CreateObject("ADODB.Connection")
Set rs=CreateObject("ADODB.RecordSet")
cn.Open "DSN=QT_Flight32"
For i=1 to 5
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set i
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
cname=window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
tickets=window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
rs.Open "select * from orders where order_number="&i,cn
If rs("customer_name")=cname and rs("tickets_ordered")=cint(tickets) Then
Reporter.ReportEvent 0,"Data","The record is matching "
else
Reporter.ReportEvent 1,"Data","The record is not matching"
End If
rs.Close
Next
cn.Close

Comments