Re: Need example of using ADO DataControl and DataGrid control - V
From: Ant (Ant_at_discussions.microsoft.com)
Date: 01/22/05
- Next message: Mark J. McGinty: "Re: multiple connection view"
- Previous message: bob bonehead: "Re: Delete an Access query using VB code"
- In reply to: L Mehl: "Re: Need example of using ADO DataControl and DataGrid control - VB6"
- Next in thread: L Mehl: "Re: Need example of using ADO DataControl and DataGrid control - V"
- Reply: L Mehl: "Re: Need example of using ADO DataControl and DataGrid control - V"
- Reply: L Mehl: "Re: Need example of using ADO DataControl and DataGrid control - V"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 22 Jan 2005 04:15:01 -0800
Hey L Mehl.
MSDN is where I learnt ADO. Just follow the little purple books via:
MSDN library - Platform SDK - Database & Messaging services - Microsoft Data
Access SDK - Microsoft ActiveX Data Objects - ADO Programmers reference -
Learning ADO
But just to get you started, here's a little code using two buttons & a
datagrid to get you going. It's only one way of doing it but it will suffice
as an example. As you'll find, you can use ADO in many differnt ways.
Just cut & paste this into a form
Ant
'*********************************************************************************
' First set a reference to the ADO object by clicking 'Project', then
scrolling *
' down to references & clicking that. Scroll down &
*
' Check 'Microsoft ActiveX Data Objects 2.X Library'. The reference is now
set. *
*
'
*
'*********************************************************************************
'Declare the objects. You need a connection object to create a conection
' to the database & a recordset object to be used as a cursor to store
' the retrieved records
Private mCn As ADODB.Connection
Private mRs As ADODB.Recordset
Private Sub Form_Load()
' Add a datagrid & two command buttons to your form
' keep the names datagrid1, command1 & command2
' Used to build the connection string & SQL string
Dim strSQL As String, strCn As String
' Instantiate the ADO object (Set the objects to the variables)
' Learn the proper way to destroy them after use. But for now don't worry.
Set mCn = New ADODB.Connection
Set mRs = New ADODB.Recordset
' Create connection string to access the database
strCn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security "
strCn = strCn & "Info=False;Initial Catalog=pubs"
' Create the query
strSQL = "SELECT TOP 10 title, notes FROM titles"
' Pass the connection the connection string then open the connection
object
With mCn
.ConnectionString = strCn
.Open
End With
' Set up the recordset. Just use these settings for now
With mRs
.ActiveConnection = mCn
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Source = strSQL
.Open
End With
' Bind the recordset to the data grid. Must use set to set an object
Set DataGrid1.DataSource = mRs
End Sub
Private Sub Command1_Click()
' Use the recordset object to scroll through the records
With mRs
' If the cursor is not before the first record (Beginning Of File)
'then move to the previous record
If Not .BOF = True Then .MovePrevious
End With
End Sub
Private Sub command2_click()
' Use the recordset object to scroll through the records
With mRs
' If the cursor is not past the last record (End Of File), then move
to the
' next record
If Not .EOF = True Then .MoveNext
End With
End Sub
- Next message: Mark J. McGinty: "Re: multiple connection view"
- Previous message: bob bonehead: "Re: Delete an Access query using VB code"
- In reply to: L Mehl: "Re: Need example of using ADO DataControl and DataGrid control - VB6"
- Next in thread: L Mehl: "Re: Need example of using ADO DataControl and DataGrid control - V"
- Reply: L Mehl: "Re: Need example of using ADO DataControl and DataGrid control - V"
- Reply: L Mehl: "Re: Need example of using ADO DataControl and DataGrid control - V"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|