473,783 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ConnectionStrin g resolves to "Provider=VFPOL EDB.1;Data
Source=C:\test\ REVFILEF.DBF;Mo de=Read|Share Deny None;Collating
Sequence=MACHIN E"

Private Function DoDBFProcess(by Val InputFileName as String) As Long
Dim RecordsExported As Long = 0, RowNumber As Long = 0
Dim Conn As New OleDb.OleDbConn ection
Dim Cmd As New OleDb.OleDbComm and
Dim Adapt As New OleDb.OleDbData Adapter
Dim Read As OleDb.OleDbData Reader
Try
Conn.Connection String = "Provider=VFPOL EDB.1;Data Source=" &
InputFileName & ";Mode=Read|Sha re Deny None;Collating Sequence=MACHIN E"
Conn.Open()
Cmd.CommandType = CommandType.Tab leDirect
Cmd.Connection = Conn
Read = Cmd.ExecuteRead er
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 4015

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 ConnectionStrin g resolves to "Provider=VFPOL EDB.1;Data
Source=C:\test\ REVFILEF.DBF;Mo de=Read|Share Deny None;Collating
Sequence=MACHIN E"

Private Function DoDBFProcess(by Val InputFileName as String) As Long
Dim RecordsExported As Long = 0, RowNumber As Long = 0
Dim Conn As New OleDb.OleDbConn ection
Dim Cmd As New OleDb.OleDbComm and
Dim Adapt As New OleDb.OleDbData Adapter
Dim Read As OleDb.OleDbData Reader
Try
Conn.Connection String = "Provider=VFPOL EDB.1;Data Source=" &
InputFileName & ";Mode=Read|Sha re Deny None;Collating Sequence=MACHIN E"
Conn.Open()
Cmd.CommandType = CommandType.Tab leDirect
Cmd.Connection = Conn
Read = Cmd.ExecuteRead er
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 ToolStripStatus Label1

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.Ole Db

Public Class Form1

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Me.ToolStripSta tusLabel1.Text = String.Empty

Dim InputFileName As String
Dim d As New OpenFileDialog
With d
.Filter = "VFP files (*.dbf)|*.dbf|A ll files (*.*)|*.* "
If Not d.ShowDialog.Eq uals(Windows.Fo rms.DialogResul t.OK)
Then Exit Sub
InputFileName = .FileName
.Dispose()
End With

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

End Sub
Private Function DoDBFProcess(By Val InputFileName As String, _
Optional ByVal MaxNumRecordToR ead As
Integer = Integer.MaxValu e) As Boolean

Dim DataTableRecord s As New DataTable
Dim Connection As New OleDbConnection

Try
With Connection
.ConnectionStri ng = "Provider=VFPOL EDB.1;Data Source="
& InputFileName & ";Mode=Read|Sha re Deny None;Collating
Sequence=MACHIN E"
.Open()
End With
Catch ex As Exception
MsgBox(ex.Messa ge)
Return False
End Try

Dim Sequential As Integer = 0
Try
Using OleDbCommandREA D As New OleDbCommand("S elect * from
revfilef", Connection)
Using OleDbDataReader As OleDbDataReader =
OleDbCommandREA D.ExecuteReader ()

DataTableRecord s = New DataTable
For i As Integer = 0 To OleDbDataReader .FieldCount
- 1
DataTableRecord s.Columns.Add(N ew
DataColumn(OleD bDataReader.Get Name(i),
OleDbDataReader .GetFieldType(i )))
Next i

Dim Values(OleDbDat aReader.FieldCo unt - 1) As
Object 'record distinti
While OleDbDataReader .Read()

Sequential += 1
If Sequential > MaxNumRecordToR ead Then Exit
While

OleDbDataReader .GetValues(Valu es)
DataTableRecord s.Rows.Add(Valu es)
End While
Me.ToolStripSta tusLabel1.Text = Sequential & "
records read through " & Connection.Prov ider

End Using
End Using

Me.DataGridView 1.DataSource = DataTableRecord s
Return True

Catch ex As Exception
MsgBox(ex.Messa ge & vbCrLf & vbCrLf)
Return False
Finally
Connection.Clos e()
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
3709
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 wasted many hours on this. Can the whole package be obtained at once with a "smart" download manager instead of having to use the VB2005 installer????? --
3
1881
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 don't see it there either. Anyone know where it is? Also, where would I find the 101 VB Code samples for VB2005? Or, indeed, some links to any VB2005 samples would be appreciated. Thanks Diarmuid
2
1319
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 to suggest the express version, but I write some pretty complicated stuff (including SQLServer transactions, network programming etc) and I am wondering what is missing from the Express version in terms of components, functionality etc. I don't...
1
1227
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 can I make VB6 do it's own debugging so it shows me the statement that causes the exception (like it always has in the past). Anyone have the answer? GalenS
0
2028
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 vb2005. But in the tools list of vb2005 I do not see a statusbar selection. Instead I see a statusStrip, and even though the Items collection has a property to set the statusStrip labels to sunken, etched,... I can see these appearances when I...
2
1609
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 design 4 your apps our group is the best to help u just subscribe to :VB2005 EXPRESS at http://groups.google.com/group/vb2005 OMAR ABID GROUP MANAGER
7
1626
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
1667
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 and use on vb2005 as when I activate the pen driver, it will run its own program itself and when I deactivate it, it become a mouse. Therefore, I need to find out how to use the pen to write words on the vb2005 program instead of being either a...
1
4440
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 can't get this button does work properly. The documentation I found in the FM20.CHM files says the button state can be determined from its "Value" property, but the property list shown in VB2005 does not have a "Value" property. How is the button...
1
2250
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 validity upon individual text box exit (don't have a problem with this part). All this could be done with Excel VBA easily, but pocket excel doesn't have VBA/Macro support. In as much, I have been trying to create a VB2005 application that I can load...
0
10313
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.