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
Ant --
Many thanks. The suggestion and code is a good start.
Larry
> Hey L Mehl.
>
[quoted text clipped - 9 lines]
> Just cut & paste this into a form
> Ant
'***************************************************************************
******
> ' First set a reference to the ADO object by clicking 'Project', then
> scrolling *
[quoted text clipped - 5 lines]
> '
> *
'***************************************************************************
******
> '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
[quoted text clipped - 58 lines]
> End With
> End Sub
Ant --
Data appears in the DataGrid just fine.
Problem:
Clicking Command1 results in
"Object required"
The code halts on
"If Not .EOF = True Then .MoveNext"
Can you tell me what causes that?
For my additional learning ...
I have seen examples of putting a not visible data connector on the form and
having that be the source for the datagrid. Is that an advanced topic from
the method you gave me, or is it a less advanced topic?
I will have many forms, most of which will have at least one datagrid, and
want to be efficient at making them all work.
Thanks,
Larry
> Hey L Mehl.
>
[quoted text clipped - 9 lines]
> Just cut & paste this into a form
> Ant
'***************************************************************************
******
> ' First set a reference to the ADO object by clicking 'Project', then
> scrolling *
[quoted text clipped - 5 lines]
> '
> *
'***************************************************************************
******
> '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
[quoted text clipped - 58 lines]
> End With
> End Sub
L Mehl - 28 Jan 2005 09:02 GMT
Ant --
My typing error caused the "Object required", so please ignore that
question.
I still need help re: "additional learning", though.
Thanks in advance.
Larry
<mehl_nospam@cyvest.com> wrote in message
news:KClKd.7614$YD5.4826@newsread3.news.pas.earthlink.net...
> Ant --
>
[quoted text clipped - 34 lines]
> > Just cut & paste this into a form
> > Ant
'***************************************************************************
> ******
> > ' First set a reference to the ADO object by clicking 'Project', then
[quoted text clipped - 6 lines]
> > '
> > *
'***************************************************************************
> ******
> >
[quoted text clipped - 64 lines]
> > End With
> > End Sub
Ant - 30 Jan 2005 02:49 GMT
Hi Larry,
VB6 doesn't offer a 'non visible data connector'- that you drag onto the
form. You might have seen a .NET example. .NET has this type of Data
connector which is quite quick to use. If you have .NET installed, it's
probably better to go down that path anyway as it's where development is
going. However VB6 will do the job quite well. If you do have .NET, you can
get good information from the .NET Newsgroup, but if not, keep playing around
with ADO as the new ADO.NET builds on the old ADO anyway. Good luck
Ant
> > For my additional learning ...
> > I have seen examples of putting a not visible data connector on the form
> and
> > having that be the source for the datagrid.
L Mehl - 30 Jan 2005 23:27 GMT
Ant --
Thanks for explaining the difference. I am heading toward dotNET, and that
is where I saw the example.
Larry
> Hi Larry,
>
[quoted text clipped - 11 lines]
> > and
> > > having that be the source for the datagrid.