473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VB2005 -> OLEDB Connectivity question

I have a VB2005 application that has the need to read FoxPro 2.5 DBF/CDX
files. I have the code (below) that opens the connection, but there are never
any records, nor errors, reported... Can anyone tell me what I'm doing
wrong?

The ConnectionString resolves to "Provider=VFPOLEDB.1;Data
Source=C:\test\REVFILEF.DBF;Mode=Read|Share Deny None;Collating
Sequence=MACHINE"

Private Function DoDBFProcess(byVal InputFileName as String) As Long
Dim RecordsExported As Long = 0, RowNumber As Long = 0
Dim Conn As New OleDb.OleDbConnection
Dim Cmd As New OleDb.OleDbCommand
Dim Adapt As New OleDb.OleDbDataAdapter
Dim Read As OleDb.OleDbDataReader
Try
Conn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=" &
InputFileName & ";Mode=Read|Share Deny None;Collating Sequence=MACHINE"
Conn.Open()
Cmd.CommandType = CommandType.TableDirect
Cmd.Connection = Conn
Read = Cmd.ExecuteReader
While Read.HasRows = True
Read.Read()
RowNumber += 1
'<Does more processing here...>
End While

Catch ex1 As Exception
Msg += ex1.Message
MsgBox(Msg)
Finally
Conn.Close()
Conn = Nothing
End Try
Return RecordsExported
End Function
Apr 7 '06 #1
2 3999

Hi Miles,

I have never worked with FoxPro, but I am experienced with several
other RDBMS.
If you can email me just one or more of those file (zipped) to make
some trial, I will be happy to try to see what's wrong and report to
you. if bigger than 2Mb please remove some records, otherwise my mail
box may refuse it. Thanks,

-tom

Miles ha scritto:
I have a VB2005 application that has the need to read FoxPro 2.5 DBF/CDX
files. I have the code (below) that opens the connection, but there are never
any records, nor errors, reported... Can anyone tell me what I'm doing
wrong?

The ConnectionString resolves to "Provider=VFPOLEDB.1;Data
Source=C:\test\REVFILEF.DBF;Mode=Read|Share Deny None;Collating
Sequence=MACHINE"

Private Function DoDBFProcess(byVal InputFileName as String) As Long
Dim RecordsExported As Long = 0, RowNumber As Long = 0
Dim Conn As New OleDb.OleDbConnection
Dim Cmd As New OleDb.OleDbCommand
Dim Adapt As New OleDb.OleDbDataAdapter
Dim Read As OleDb.OleDbDataReader
Try
Conn.ConnectionString = "Provider=VFPOLEDB.1;Data Source=" &
InputFileName & ";Mode=Read|Share Deny None;Collating Sequence=MACHINE"
Conn.Open()
Cmd.CommandType = CommandType.TableDirect
Cmd.Connection = Conn
Read = Cmd.ExecuteReader
While Read.HasRows = True
Read.Read()
RowNumber += 1
'<Does more processing here...>
End While

Catch ex1 As Exception
Msg += ex1.Message
MsgBox(Msg)
Finally
Conn.Close()
Conn = Nothing
End Try
Return RecordsExported
End Function


Apr 7 '06 #2

hi Miles,

thank you for the file.

Assume VB2005, Visual Fox Pro OleDb Driver
Free download:
http://www.microsoft.com/downloads/d...displaylang=en

[install the exe, minimal ok, no reboot needed]

Assume a Form1 with DataGridView1 and ToolStripStatusLabel1

Posting here (slightly improved version) so that other can propose
improvements (very welcome). If need VB2003 or have problems just let
me know....

-tommaso
[Datatime Free Project]

'----------------------------------------------------------------------------

Imports System.Data.OleDb

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.ToolStripStatusLabel1.Text = String.Empty

Dim InputFileName As String
Dim d As New OpenFileDialog
With d
.Filter = "VFP files (*.dbf)|*.dbf|All files (*.*)|*.* "
If Not d.ShowDialog.Equals(Windows.Forms.DialogResult.OK)
Then Exit Sub
InputFileName = .FileName
.Dispose()
End With

If Me.DoDBFProcess(InputFileName) Then
Me.ToolStripStatusLabel1.Text = "Records read OK"

End Sub
Private Function DoDBFProcess(ByVal InputFileName As String, _
Optional ByVal MaxNumRecordToRead As
Integer = Integer.MaxValue) As Boolean

Dim DataTableRecords As New DataTable
Dim Connection As New OleDbConnection

Try
With Connection
.ConnectionString = "Provider=VFPOLEDB.1;Data Source="
& InputFileName & ";Mode=Read|Share Deny None;Collating
Sequence=MACHINE"
.Open()
End With
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try

Dim Sequential As Integer = 0
Try
Using OleDbCommandREAD As New OleDbCommand("Select * from
revfilef", Connection)
Using OleDbDataReader As OleDbDataReader =
OleDbCommandREAD.ExecuteReader()

DataTableRecords = New DataTable
For i As Integer = 0 To OleDbDataReader.FieldCount
- 1
DataTableRecords.Columns.Add(New
DataColumn(OleDbDataReader.GetName(i),
OleDbDataReader.GetFieldType(i)))
Next i

Dim Values(OleDbDataReader.FieldCount - 1) As
Object 'record distinti
While OleDbDataReader.Read()

Sequential += 1
If Sequential > MaxNumRecordToRead Then Exit
While

OleDbDataReader.GetValues(Values)
DataTableRecords.Rows.Add(Values)
End While
Me.ToolStripStatusLabel1.Text = Sequential & "
records read through " & Connection.Provider

End Using
End Using

Me.DataGridView1.DataSource = DataTableRecords
Return True

Catch ex As Exception
MsgBox(ex.Message & vbCrLf & vbCrLf)
Return False
Finally
Connection.Close()
End Try

End Function

End Class

Apr 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Chris Devol | last post by:
My dial-up connection sometimes hangs up and has to re-connect. The VB2005 installer/downloader apparently doesn't know how to resume when the connection is re-established. It just aborts! I've...
3
by: Diarmuid | last post by:
I have the MS book, introducing Microsoft Visual Basic 2005 for Developers. No sample code comes with it.The location according to the book is http://msdn.microsoft.com/vbasic/VB6Migration but I...
2
by: Jerry Spence1 | last post by:
1. Is there a more suitable, dedicated newsfeed for VB2005 yet? 2. I'm confused as to which version to get. I work for a small company and we will just need VB2005 on my PC. Therefore that tends...
1
by: Galen Somerville | last post by:
I uninstalled and reinstalled VB6. When I have an unhandled exception in VB6, it uses the VB2005 Pro debugger. There is no way to leave the VB2005 debugger without ending up at the desktop. How...
0
by: Rich | last post by:
Hello, I just upgraded a vb2003 app to vb2005. The vb2003 app had/has a statusbar object - which contains panels and I can see the properties of the statusbar in the properties window in...
2
by: Omar Abid | last post by:
Hi, This the best site where you can find Hi members, We are happy to tell that if you search for : jobs with high wage or to debug a program or to find a good source code and to make a good...
7
by: TAVOSOFT | last post by:
Hi friends, I am begginer , I wanna to learn VB2005 ,Which are good book for to learn VB2005 of level -begginer-intermediate. Thanks you friends.
1
by: erickwan88 | last post by:
I am doing a final year project for my school and is going to provide for an organization, so I am asking for some help on here. Indeed, I have no idea on how to get the input from my pen driver...
1
by: Jeffrey Christiansen | last post by:
I wanted to add a toggle button to a VB2005 form to be used for a simple Windows Application (i.e. compiled to a "*.exe"), so I added the ActiveX Microsoft Forms Object toggle button, however I...
1
by: Vae07 | last post by:
Ok so here is a brief summary of my problem. I need a pop up form that submits input text box information to a pocket excel workbook upon a command botton click. Text box inputs are checked for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.