473,508 Members | 3,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening a dbf file with .NET code

I have a simple dbf file with the name of OTHWAGE.dbf. I can open it in
Visual Studio Server Explorer and see its fields and records by creating a
Data Connection. When I copy the connection string and combine it with code
from VS Help, I end up with the following:

Dim sConnection As String = "Provider=MSDASQL.1;
Persist Security Info=False;
Data Source=dBASE Files;
Extended Properties=""DSN=dBASE Files;DBQ=C:\Temp;
DefaultDir=c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE;
DriverId=533;MaxBufferSize=2048;
PageTimeout=5
;"";
Initial Catalog=C:\Temp"

Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
Dim myConnection As New System.Data.Odbc.OdbcConnection(sConnection)
Dim myCommand As New System.Data.Odbc.OdbcCommand(mySelectQuery,
myConnection)
myConnection.Open()
Dim myReader As
System.Data.Odbc.OdbcDataReader = myCommand.ExecuteReader()
While myReader.Read()
Console.WriteLine(myReader.GetString(1))
End While

For readability purposes, I added carriage returns to the connection string.
When I execute this code, I get a system error at the myConnection.Open()
line. What I am I doing wrong with this simple code?
Nov 21 '05 #1
4 14347
Hi Joe,

First off, try the FoxPro and Visual FoxPro OLE DB data provider, available
from http://msdn.microsoft.com/vfoxpro/downloads/updates . For your
connection string use:

"Provider=VFPOLEDB.1;Data Source = C:\Temp;"

That's all you need for free tables. If you still have problems, post back.

--
Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
ci**************@msn.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden
"genojoe" <ge*****@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
I have a simple dbf file with the name of OTHWAGE.dbf. I can open it in
Visual Studio Server Explorer and see its fields and records by creating a
Data Connection. When I copy the connection string and combine it with
code
from VS Help, I end up with the following:

Dim sConnection As String = "Provider=MSDASQL.1;
Persist Security Info=False;
Data Source=dBASE Files;
Extended Properties=""DSN=dBASE Files;DBQ=C:\Temp;
DefaultDir=c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE;
DriverId=533;MaxBufferSize=2048;
PageTimeout=5
;"";
Initial Catalog=C:\Temp"

Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
Dim myConnection As New
System.Data.Odbc.OdbcConnection(sConnection)
Dim myCommand As New System.Data.Odbc.OdbcCommand(mySelectQuery,
myConnection)
myConnection.Open()
Dim myReader As
System.Data.Odbc.OdbcDataReader = myCommand.ExecuteReader()
While myReader.Read()
Console.WriteLine(myReader.GetString(1))
End While

For readability purposes, I added carriage returns to the connection
string.
When I execute this code, I get a system error at the myConnection.Open()
line. What I am I doing wrong with this simple code?

Nov 21 '05 #2
I agree it should work. This time I even began a new project (on same
computer). One form, one button. FoxPro provider worked great in the Server
Explorer.

I crash at last line of code shown below:

Dim sConnection As String = "Provider=VFPOLEDB.1;Data Source = C:\Temp;"
Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
Dim myConnection As New System.Data.Odbc.OdbcConnection(sConnection)
Dim myCommand As New System.Data.Odbc.OdbcCommand(mySelectQuery, myConnection)

myConnection.Open()

Error message is:
An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in
system.data.dll

Additional information: System error.

Thank you for the response. Any more thoughts?
==================

"Cindy Winegarden" wrote:
Hi Joe,

First off, try the FoxPro and Visual FoxPro OLE DB data provider, available
from http://msdn.microsoft.com/vfoxpro/downloads/updates . For your
connection string use:

"Provider=VFPOLEDB.1;Data Source = C:\Temp;"

That's all you need for free tables. If you still have problems, post back.

--
Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
ci**************@msn.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden

Nov 21 '05 #3
I got the following to work:

Dim myConnection As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source=C:\TEMP;Extended Properties=dBase III")
Dim myCommand As New System.Data.OleDb.OleDbCommand("SELECT
OTHWAGE.* FROM OTHWAGE", myConnection)
myConnection.Open()
Dim myReader As System.Data.OleDb.OleDbDataReader =
myCommand.ExecuteReader()
While myReader.Read()
Debug.WriteLine(CStr(myReader.GetValue(0)))
End While
"Cindy Winegarden" wrote:
Hi Joe,

First off, try the FoxPro and Visual FoxPro OLE DB data provider, available


Nov 21 '05 #4
Hi Joe,

I'm glad you found a work-around.

--
Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
ci**************@msn.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden
"genojoe" <ge*****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
I got the following to work:

Dim myConnection As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source=C:\TEMP;Extended Properties=dBase III")
Dim myCommand As New System.Data.OleDb.OleDbCommand("SELECT
OTHWAGE.* FROM OTHWAGE", myConnection)
myConnection.Open()
Dim myReader As System.Data.OleDb.OleDbDataReader =
myCommand.ExecuteReader()
While myReader.Read()
Debug.WriteLine(CStr(myReader.GetValue(0)))
End While
"Cindy Winegarden" wrote:
Hi Joe,

First off, try the FoxPro and Visual FoxPro OLE DB data provider,
available

Nov 21 '05 #5

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

Similar topics

5
714
by: PM | last post by:
Has anyone found a way to open a file exclusively where it will fail if the file is already open, i have tried the following _FileStream = new FileStream(@"C:\Data.txt", FileMode.Open,...
1
4381
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
14
11017
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
0
1519
by: John Winterbottom | last post by:
Does anyone know if this is possible? We are running Access XP with Windows XP Prof.. We have an ADP file we are using to print custom reports for a client. It's opened and conntrolled through...
5
3304
by: Brad | last post by:
In several aspx applications I export crytal reports to pdf, xls and doc files and then the aspx page writes the selected export file to the client browser. This all works with one small quirk: ...
11
3570
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
1
1935
by: gangs | last post by:
I need to know how can I open a file which is named using UTF-16 encoding in unicode. I am desperately trying to open the file using the wofstream typedef, but even it takes the parameter as const...
9
2296
compman9902
by: compman9902 | last post by:
Hello, and thank toy for reading this post. Thus far, this website has helped me a lot, (I have finally finished my encryptor: "site removed by moderator", go to the downloads link) and I will...
15
2213
by: Umesh | last post by:
how to open a website like yahoo.com and use it as input? The following code doesn't work. #include"stdio.h" int main() { FILE *f; f=fopen("http://www.yahoo.com","r"); if(f==NULL)
34
5297
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
0
7228
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
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7393
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...
1
7058
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...
0
5635
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,...
1
5057
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...
0
4715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
426
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...

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.