FoxPro Tables in VB?!?! 
Author Message
 FoxPro Tables in VB?!?!

I'm trying to access FoxPro 7.0 tables from VB using ADO, but I'm not having
much luck.  I'm able to connect using this string:

****************************************************************************
******
Global Const gsFoxProConnectionString = "Provider=vfpoledb;Data
Source=c:\JFLTime\data\JFLTime.dbc"
****************************************************************************
******

I then try to load a combo box with data from a table with the following
code:

****************************************************************************
*******
   Dim tmpConnection As ADODB.Connection
   Dim tmpRecordset As ADODB.Recordset
   Dim Index As Integer

   Set tmpConnection = New ADODB.Connection
   Set tmpRecordset = New ADODB.Recordset

   tmpConnection.Open (gsFoxProConnectionString)

    tmpRecordset.Open "SELECT * FROM " + sTableName, tmpConnection
   If (tmpRecordset.RecordCount) Then
      tmpRecordset.MoveFirst
      For Index = 1 To tmpRecordset.RecordCount
         If Not IsNull(tmpRecordset.Fields(sFieldName)) Then
            ThisCombo.AddItem tmpRecordset.Fields(sFieldName)
         End If
         tmpRecordset.MoveNext
      Next Index
   End If
   tmpRecordset.Close
   tmpConnection.Close
****************************************************************************
***********

The problem is that the record count for tmpRecordset is coming back as -1,
indicating of course that there are no records in the table.  But there are.
Is there something in the connection string that's messed up?  I'm not
getting any error messages, just an empty recordset.  HELP!!!



Sat, 03 Sep 2005 00:31:01 GMT  
 FoxPro Tables in VB?!?!
I have that same problem. Workaround is using recordset.BOF and
recordset.EOF

If Not temp.recordset.BOF And Not temp.recordset.EOF Then
    temp.recordset.movefirst
    while not temp.recordset.eof
        ...processing statements here
    wend
end if

HTH

JL

Quote:
> I'm trying to access FoxPro 7.0 tables from VB using ADO, but I'm not
having
> much luck.  I'm able to connect using this string:

****************************************************************************
Quote:
> ******
> Global Const gsFoxProConnectionString = "Provider=vfpoledb;Data
> Source=c:\JFLTime\data\JFLTime.dbc"

****************************************************************************
Quote:
> ******

> I then try to load a combo box with data from a table with the following
> code:

****************************************************************************
Quote:
> *******
>    Dim tmpConnection As ADODB.Connection
>    Dim tmpRecordset As ADODB.Recordset
>    Dim Index As Integer

>    Set tmpConnection = New ADODB.Connection
>    Set tmpRecordset = New ADODB.Recordset

>    tmpConnection.Open (gsFoxProConnectionString)

>     tmpRecordset.Open "SELECT * FROM " + sTableName, tmpConnection
>    If (tmpRecordset.RecordCount) Then
>       tmpRecordset.MoveFirst
>       For Index = 1 To tmpRecordset.RecordCount
>          If Not IsNull(tmpRecordset.Fields(sFieldName)) Then
>             ThisCombo.AddItem tmpRecordset.Fields(sFieldName)
>          End If
>          tmpRecordset.MoveNext
>       Next Index
>    End If
>    tmpRecordset.Close
>    tmpConnection.Close

****************************************************************************

- Show quoted text -

Quote:
> ***********

> The problem is that the record count for tmpRecordset is coming back
as -1,
> indicating of course that there are no records in the table.  But there
are.
> Is there something in the connection string that's messed up?  I'm not
> getting any error messages, just an empty recordset.  HELP!!!



Sat, 03 Sep 2005 01:55:04 GMT  
 FoxPro Tables in VB?!?!
I don't know if it will help, but there's an updated VFP OLE DB provider
included in the VFP8 download for MSDN subscribers. The updated provider
will most likely be available for public download from the VFP website in
mid April.

--
Cindy Winegarden  MCSD, Microsoft Visual FoxPro MVP

http://msdn.microsoft.com/vfoxpro  http://foxcentral.net


Quote:
> I'm trying to access FoxPro 7.0 tables from VB using ADO, but I'm not
> having
> much luck.  I'm able to connect using this string:
> Global Const gsFoxProConnectionString = "Provider=vfpoledb;Data
> Source=c:\JFLTime\data\JFLTime.dbc"



Sat, 03 Sep 2005 02:35:33 GMT  
 FoxPro Tables in VB?!?!
Curt,

A return value of -1 from the RecordCount property indicates that this
function is not supported given the type of ADO cursor retrieved.

To obtain a cursor type that will have a usable value in the RecordCount,
make the connection or recordset CursorLocation property = 3. (adUseClient)

Ex:
tmpConnection.CursorLocation = 3 && adUseClient
tmpConnection.Open (gsFoxProConnectionString)

Hope this helps,
Crescencio


Quote:
> I'm trying to access FoxPro 7.0 tables from VB using ADO, but I'm not
having
> much luck.  I'm able to connect using this string:

****************************************************************************
Quote:
> ******
> Global Const gsFoxProConnectionString = "Provider=vfpoledb;Data
> Source=c:\JFLTime\data\JFLTime.dbc"

****************************************************************************
Quote:
> ******

> I then try to load a combo box with data from a table with the following
> code:

****************************************************************************
Quote:
> *******
>    Dim tmpConnection As ADODB.Connection
>    Dim tmpRecordset As ADODB.Recordset
>    Dim Index As Integer

>    Set tmpConnection = New ADODB.Connection
>    Set tmpRecordset = New ADODB.Recordset

>    tmpConnection.Open (gsFoxProConnectionString)

>     tmpRecordset.Open "SELECT * FROM " + sTableName, tmpConnection
>    If (tmpRecordset.RecordCount) Then
>       tmpRecordset.MoveFirst
>       For Index = 1 To tmpRecordset.RecordCount
>          If Not IsNull(tmpRecordset.Fields(sFieldName)) Then
>             ThisCombo.AddItem tmpRecordset.Fields(sFieldName)
>          End If
>          tmpRecordset.MoveNext
>       Next Index
>    End If
>    tmpRecordset.Close
>    tmpConnection.Close

****************************************************************************

- Show quoted text -

Quote:
> ***********

> The problem is that the record count for tmpRecordset is coming back as -1
,
> indicating of course that there are no records in the table.  But there
are.
> Is there something in the connection string that's messed up?  I'm not
> getting any error messages, just an empty recordset.  HELP!!!



Sat, 03 Sep 2005 05:13:07 GMT  
 FoxPro Tables in VB?!?!
RecordCount also does not return a positive value for recordsets opened with
adOpenForwardOnly, which then requires that you use the EOF and BOF
properties to manage the recordset.

Hope that helps...



Quote:
> Curt,

> A return value of -1 from the RecordCount property indicates that this
> function is not supported given the type of ADO cursor retrieved.

> To obtain a cursor type that will have a usable value in the RecordCount,
> make the connection or recordset CursorLocation property = 3.
(adUseClient)

> Ex:
> tmpConnection.CursorLocation = 3 && adUseClient
> tmpConnection.Open (gsFoxProConnectionString)

> Hope this helps,
> Crescencio



> > I'm trying to access FoxPro 7.0 tables from VB using ADO, but I'm not
> having
> > much luck.  I'm able to connect using this string:

****************************************************************************
Quote:
> > ******
> > Global Const gsFoxProConnectionString = "Provider=vfpoledb;Data
> > Source=c:\JFLTime\data\JFLTime.dbc"

****************************************************************************
Quote:
> > ******

> > I then try to load a combo box with data from a table with the following
> > code:

****************************************************************************

- Show quoted text -

Quote:
> > *******
> >    Dim tmpConnection As ADODB.Connection
> >    Dim tmpRecordset As ADODB.Recordset
> >    Dim Index As Integer

> >    Set tmpConnection = New ADODB.Connection
> >    Set tmpRecordset = New ADODB.Recordset

> >    tmpConnection.Open (gsFoxProConnectionString)

> >     tmpRecordset.Open "SELECT * FROM " + sTableName, tmpConnection
> >    If (tmpRecordset.RecordCount) Then
> >       tmpRecordset.MoveFirst
> >       For Index = 1 To tmpRecordset.RecordCount
> >          If Not IsNull(tmpRecordset.Fields(sFieldName)) Then
> >             ThisCombo.AddItem tmpRecordset.Fields(sFieldName)
> >          End If
> >          tmpRecordset.MoveNext
> >       Next Index
> >    End If
> >    tmpRecordset.Close
> >    tmpConnection.Close

****************************************************************************

- Show quoted text -

Quote:
> > ***********

> > The problem is that the record count for tmpRecordset is coming back
as -1
> ,
> > indicating of course that there are no records in the table.  But there
> are.
> > Is there something in the connection string that's messed up?  I'm not
> > getting any error messages, just an empty recordset.  HELP!!!



Sat, 03 Sep 2005 15:23:09 GMT  
 FoxPro Tables in VB?!?!
Given the code he was using, adding CursorLocation = 3 (adUseClient) on the
connection object is sufficient. This would yield a CursorType = 3
(adOpenStatic) which you can get a good RecordCount from.

Cheers,
Crescencio


Quote:
> RecordCount also does not return a positive value for recordsets opened
with
> adOpenForwardOnly, which then requires that you use the EOF and BOF
> properties to manage the recordset.

> Hope that helps...



> > Curt,

> > A return value of -1 from the RecordCount property indicates that this
> > function is not supported given the type of ADO cursor retrieved.

> > To obtain a cursor type that will have a usable value in the
RecordCount,
> > make the connection or recordset CursorLocation property = 3.
> (adUseClient)

> > Ex:
> > tmpConnection.CursorLocation = 3 && adUseClient
> > tmpConnection.Open (gsFoxProConnectionString)

> > Hope this helps,
> > Crescencio



> > > I'm trying to access FoxPro 7.0 tables from VB using ADO, but I'm not
> > having
> > > much luck.  I'm able to connect using this string:

****************************************************************************
Quote:
> > > ******
> > > Global Const gsFoxProConnectionString = "Provider=vfpoledb;Data
> > > Source=c:\JFLTime\data\JFLTime.dbc"

****************************************************************************
Quote:
> > > ******

> > > I then try to load a combo box with data from a table with the
following
> > > code:

****************************************************************************

- Show quoted text -

Quote:
> > > *******
> > >    Dim tmpConnection As ADODB.Connection
> > >    Dim tmpRecordset As ADODB.Recordset
> > >    Dim Index As Integer

> > >    Set tmpConnection = New ADODB.Connection
> > >    Set tmpRecordset = New ADODB.Recordset

> > >    tmpConnection.Open (gsFoxProConnectionString)

> > >     tmpRecordset.Open "SELECT * FROM " + sTableName, tmpConnection
> > >    If (tmpRecordset.RecordCount) Then
> > >       tmpRecordset.MoveFirst
> > >       For Index = 1 To tmpRecordset.RecordCount
> > >          If Not IsNull(tmpRecordset.Fields(sFieldName)) Then
> > >             ThisCombo.AddItem tmpRecordset.Fields(sFieldName)
> > >          End If
> > >          tmpRecordset.MoveNext
> > >       Next Index
> > >    End If
> > >    tmpRecordset.Close
> > >    tmpConnection.Close

****************************************************************************

- Show quoted text -

Quote:
> > > ***********

> > > The problem is that the record count for tmpRecordset is coming back
> as -1
> > ,
> > > indicating of course that there are no records in the table.  But
there
> > are.
> > > Is there something in the connection string that's messed up?  I'm not
> > > getting any error messages, just an empty recordset.  HELP!!!



Sat, 03 Sep 2005 23:00:14 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. alter table, vb and foxpro

2. DSNLess connection to Visual FoxPro table from Access 2000 using VB

3. how VB update Table A INNER JOIN Table B, Set A.co=B.ID

4. how VB update Table A INNER JOIN Table B, Set A.co=B.ID

5. FP Tables with VB Front End

6. how to use VB open two MSaccess tables in one form

7. how to use VB open two MSaccess tables in one form

8. Packing a Table from a VB Front End

9. Packing a Table from VB

10. Give VB Programs a taste of DBF tables

11. VFP50 - VB and VFP 3.0 tables

12. Problems update tables using VB

 

 
Powered by phpBB® Forum Software