Originally Posted by
chlark
try daw ni ug basa2x TS, hinaut ma ok na imo ulo ani...
Option explicit
Dim cono, rso, onum, expected, actual
'Read testdata
onum=inputbox("Enter order number")
expected=inputbox("Enter customer name")
expected=cstr(expected)
'Connect to DB
Set cono=createobject("ADODB.Connection")
cono.Open("DSN=QT_Flight32")
'Update DB
cono.Execute "Update orders set Customer_Name='"&expected&"' where order_number="&onum
'select data from DB
Set rso=createobject("ADODB.Recordset")
rso.Open "select Customer_Name from orders where order_number="&onum,cono
actual=rso.Fields("Customer_Name").Value
If cstr(expected)=cstr(actual) Then
reporter.ReportEvent micPass,"DB testing","Correctly updated"
else
reporter.ReportEvent micFail,"DB testing","Incorrectly updated"
End If
rso.Close
cono.Close
Set rso=nothing
Set cono=nothing
--------------------------------------------
Option explicit
Dim cono, rso, x
Set cono=createobject("ADODB.Connection")
cono.Open("DSN=QT_Flight32")
Set rso=createobject("ADODB.Recordset")
rso.Open "Select Order_number from orders where tickets_ordered>5",cono
While rso.EOF<>true
x=rso.Fields("Order_Number").Value
cono.Execute "Update orders set tickets_ordered=5 where order_number="&x
rso.MoveNext
Wend
rso.Close
cono.Close
--------------------------------------------
Option explicit
Dim cono, rso, x
'connect to database
Set cono=createobject("adodb.connection")
cono.Open ("dsn=qt_flight32")
'select all customer names
Set rso=createobject("adodb.recordset")
rso.Open "select customer_name from orders",cono
'Disply customer names which starts with capital
While rso.EOF<>true
x=rso.Fields("customer_name").Value
If left(x,1)>="A" and left(x,1)<="Z" Then
print x
End If
rso.MoveNext
Wend
rso.Close
cono.Close
------------------------------------------------------------
Option explicit
Dim cono, rso, x, y, flag
'Connect to DB
x=inputbox("Enter order number")
Set cono=createobject("ADODB.Connection")
cono.Open("DSN=QT_Flight32")
'Delete specified record
cono.Execute "Delete from orders where Order_Number="&x
'Select all Orders
Set rso=createobject("ADODB.Recordset")
rso.Open "Select Order_number from orders",cono
flag=0
While rso.EOF<>true
y=rso.Fields("Order_Number").Value
If x=y Then
flag=1
End If
rso.MoveNext
Wend
If flag=0 Then
Reporter.ReportEvent micPass,"DB test","Deleted"
else
Reporter.ReportEvent micFail,"DB test","Not Deleted"
End If
rso.Close
cono.close
---------------------------------------------------------------------
Option explicit
Dim cono, rso, noc, i, cn
Set cono=createobject("ADODB.Connection")
cono.Open("DSN=QT_Flight32")
Set rso=createobject("ADODB.Recordset")
rso.Open "select * from orders",cono
noc=rso.Fields.Count
For i=0 to noc-1 step 1
cn=rso.Fields(i).Name
print cn
Next
rso.Close
cono.Close
Set rso=nothing
Set cono=nothing
--------------------------------------------------------
Option explicit
Dim cono, rso, noc
Set cono=createobject("ADODB.connection")
cono.open("Provider=SQLOLEDB; Server=SYS; Database=master; Trusted_Connection=yes;")
Set rso=createobject("ADODB.recordset")
rso.Open "select * from DBO.Spt_values", cono
noc=rso.Fields.Count
print "no. of columns in data table" &noc
rso.Close
cono.close
-------------------------------------------------------
Fetching the Data From Data base and storing the results in Excel Sheet
Option explicit
Dim exo, wbo, wso, cono, rso, noc, i, j
'create excel file
Set exo=createobject("Excel.Application")
exo.Visible=true
Set wbo=exo.Workbooks.Add
Set wso=wbo.Worksheets("Sheet1")
'Connect to DB and get data
Set cono=createobject("adodb.connection")
cono.Open("DSN=qt_flight32")
Set rso=createobject("adodb.recordset")
rso.Open "select * from orders",cono
noc=rso.Fields.Count
'create columns in excel
For i=0 to noc-1 step 1
wso.cells(1, i+1)=rso.Fields(i).Name
Next
'Rows storing
j=2
While rso.EOF<>true
For i=0 to noc-1 step 1
wso.cells(j, i+1)=rso.Fields(i).Value
Next
rso.MoveNext
j=j+1
Wend
wbo.SaveAs("C:\mydb.xls")
rso.Close
cono.Close
exo.Quit
Set rso=nothing
Set cono=nothing
Set wso=nothing
Set wbo=nothing
Set exo=nothing
----------------------------------------------------------
Fetching the Data From Data base and storing the results in Data Table
Option explicit
Dim cono, rso, noc, i, j, x
'Connect to DB and get data
Set cono=createobject("adodb.connection")
cono.Open("DSN=qt_flight32")
Set rso=createobject("adodb.recordset")
rso.Open "select * from orders",cono
noc=rso.Fields.Count
'create columns in Datatable
For i=0 to noc-1 step 1
x=rso.Fields(i).Name
datatable.GetSheet(1).AddParameter x,""
Next
j=1
'Rows storing
While rso.EOF<>true
datatable.GetSheet(1).SetCurrentRow(j)
For i=0 to noc-1 step 1
y=rso.Fields(i).Value
datatable.Value(i+1,1)=y
Next
rso.MoveNext
j=j+1
Wend
rso.Close
cono.Close
Set rso=nothing
Set cono=nothing