MS_SQLADO Class |
Top Previous Next |
The MS_SQLADO Class that is in the default Commando Script project is a very simple class. It's provided to you as an example of some of the possibilities available to you when designing your own classes as well as being something that's totally functional that you might be able to use right out of the box.
Example Usage:
Private Sub TestDBConnection()
Dim oCONN, oRS, sSQL
Set oCONN = New MS_SQLADO
With oCONN .ServerName = oUTILITIES.MyComputerName .DatabaseName = "Northwind" .UserID = "SA" .Password = "<password>" .Timeout = 30 If Not .Connect() Then SMEvent.Raise "TRACE", .LastError Set oCONN = Nothing Exit Sub End If 'Now we've established a connection to the database, let's open a recordset sSQL = "Select * From Customers Where CompanyName Like 'A%' Order By CompanyName" Set oRS = .OpenReadOnlyRS(sSQL) If .IsError Then SMEvent.Raise "TRACE", .LastError Set oCONN = Nothing Exit Sub End If 'Now we'll just loop through the recordset and trace the company names into the processor window SMEvent.Raise "TRACE", "Opened customers table" Do While Not oRS.Eof SMEvent.Raise "TRACE", "Customer: " & CStr(oRS("CustomerName") & "") oRS.MoveNext 'Since we're looping and don't know how many iterations we've got, we'd better do a yield call 'so that this script doesn't hog the CPU. oUTILITIES.Yield 'Check to see if the user needs to cancel If oUTILITIES.Cancel Then oRS.Close Set oRS = Nothing Set oCONN = Nothing Exit Sub End If Loop oRS.Close Set oRS = Nothing Set oCONN = Nothing Exit Sub End With
End Sub |