Hello Data Code

Hello Data Code

Hello Data Code

Hello Data Code
Hello Data Code

BeginHelloDataOption Explicit Dim m_oRecordset1 As ADODB.RecordsetDim m_sConnStr As StringDim m_flgPriceUpdated As Boolean

Private Sub cmdEditData_Click()     


End Sub

Private Sub cmdExamineData_Click()      


End Sub

Private Sub cmdGetData_Click()

       GetData End Sub

Private Sub cmdUpdateData_Click()


End Sub

Private Sub GetData()

Dim sSQL As String

Dim oConnection1 As ADODB.Connection

m_sConnStr = “Provider=SQLOLEDB;Data Source=MySrvr;” & _

“Initial Catalog=Northwind;User d=MyId;Password=123aBc;”

On Error GoTo GetDataError

‘ Create and Open the Connection object.

Set oConnection1 = New ADODB.Connection

oConnection1.CursorLocation = adUseClient

oConnection1.Open m_sConnStr

sSQL = “SELECT ProductID, ProductName, CategoryID, UnitPrice ” & _

“FROM Product”

‘ Create and Open the Recordset object.

Set m_oRecordset1 = New ADODB.Recordset

m_oRecordset1.Open sSQL, oConnection1, adOpenStatic, _

adLockBatchOptimistic, adCmdText

m_oRecordset1.MarshalOptions = adMarshalModifiedOnly

‘ Disconnect the Recordset.

Set m_oRecordset1.ActiveConnection = Nothing


Set oConnection1 = Nothing

‘ Bind Recordset to the DataGrid for display.

Set grdDisplay1.DataSource = m_oRecordset1

Exit Sub


If oConnection1 Is Nothing Then

HandleErrs “GetData”, m_oRecordset1.ActiveConnection


HandleErrs “GetData”, oConnection1

End If

End Sub

Private Sub ExamineData()

Dim iNumRecords As Integer

Dim vBookmark As Variant

On Err GoTo ExamineDataErr

iNumRecords = m_oRecordset1.RecordCount

DisplayMsg “There are ” & CStr(iNumRecords) & _

” records in the current Recordset.”

‘ Loop through the Recordset and print the

‘ value of the AbsolutePosition property.

DisplayMsg “****** Start AbsolutePosition Loop ******”

Do While Not m_oRecordset1.EOF

‘ Store the bookmark for the 3rd record,

‘ for demo purposes.

If m_oRecordset1.AbsolutePosition = 3 Then _

vBookmark = m_oRecordset1.Bookmark

DisplayMsg m_oRecordset1.AbsolutePosition



DisplayMsg “****** End AbsolutePosition Loop ******” & vbCrLf

‘ Use our bookmark to move back to 3rd record.

m_oRecordset1.Bookmark = vBookmark

MsgBox vbCr & “Moved back to position ” & _

m_oRecordset1.AbsolutePosition & ” using bookmark.”, , _

“Hello Data”

‘ Display meta-data about each field. See WalkFields() sub.

Call WalkFields

‘ Apply a filter on the type field.

MsgBox “Filtering on type field. (CategoryID=2)”, _

vbOKOnly, “Hello Data”

m_oRecordset1.Filter = “CategoryID=2”

Exit Sub


HandleErrs “ExamineData”, m_oRecordset1.ActiveConnection

End Sub

Private Sub EditData()

On Error GoTo EditDataErr

‘Recordset still filtered on CategoryID=2.

‘Increase price by 10% for filtered records.

MsgBox “Increasing unit price by 10%” & vbCr & _

“for all records with CategoryID = 2.”, , “Hello Data”


Dim cVal As Currency

Do While Not m_oRecordset1.EOF

cVal = m_oRecordset1.Fields(“UnitPrice”).Value

m_oRecordset1.Fields(“UnitPrice”).Value = (cVal * 1.1)


Baca Juga  :