Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dBase ADO & C#

1 view
Skip to first unread message

Burhan H. Afandi

unread,
Jul 15, 2001, 4:26:03 PM7/15/01
to
Can someone show an example of how to access a dBase using C# and ADO?

Jesse Liberty

unread,
Jul 15, 2001, 8:33:41 PM7/15/01
to
I assume you mean ADO.NET

There are a number of ways to accomplish the same thing. The most powerful
is probably to create a DataSet:

string connectionString =
"server=YourServer; uid=sa;
pwd=YourPassword; database=YourDB";

// get records from the the table
string commandString =
"Select foo, bar from myTable";

// create the data set command object
// and the DataSet
SqlDataAdapter dataAdapter =
new SqlDataAdapter(
commandString, connectionString);

DataSet dataSet = new DataSet();

// fill the data set object
dataAdapter.Fill(dataSet,"myTable");


--
Jesse Liberty
Liberty Associates, Inc.
.NET Training & Development
http://www.LibertyAssociates.com


"Burhan H. Afandi" <baf...@hotmail.com> wrote in message
news:OCqSOxWDBHA.1368@tkmsftngp04...

Burhan H. Afandi

unread,
Jul 17, 2001, 2:12:37 AM7/17/01
to
Thanks but this code doesn't seem to work for me.

I am trying to access a dBase database file. I tried your code and
variations of it but it didn't work.

Thanks anyway

"Jesse Liberty" <jlib...@libertyassociates.com> wrote in message
news:e16537YDBHA.1416@tkmsftngp04...

Jesse Liberty

unread,
Jul 17, 2001, 7:36:53 AM7/17/01
to
I'm sorry, but you need to provide more specific information if you want
help with this. What didn't work? What was the error? Did it thrown an
exception? Etc.

Make sure you set the correct database, password, etc.

--
Jesse Liberty
Liberty Associates, Inc.
.NET Training & Development
http://www.LibertyAssociates.com


"Burhan H. Afandi" <baf...@hotmail.com> wrote in message

news:u#9GrdoDBHA.1772@tkmsftngp02...

Burhan H. Afandi

unread,
Jul 17, 2001, 9:57:11 AM7/17/01
to

I am still using Beta 1 of VS.NET, I guess my shipment got lost in the mail.

Anyway this is how I accessed the database using VB 6

Dim db As New adodb.Connection

db.CursorLocation = adUseServer

db.Open "PROVIDER=MSDASQL;driver=Microsoft dBase Driver
(*.dbf);server=c:\windows\desktop\;uid=;pwd=;database=myfolder"

Dim rs As New adodb.Recordset

rs.CursorType = adOpenDynamic

rs.LockType = adLockOptimistic

rs.ActiveConnection = db

rs.Open "select FNAME,LNAME,HPHONE,MPHONE from
c:\windows\desktop\myfolder\friends.dbf"

rs.MoveFirst

"Jesse Liberty" <jlib...@libertyassociates.com> wrote in message

news:OcfQOZrDBHA.1500@tkmsftngp02...

Nathan Silva

unread,
Jul 18, 2001, 6:36:05 PM7/18/01
to
Unfortunately, you can't. According to the documentation: "The OLE DB .NET
Data Provider does not work with the OLE DB Provider for ODBC (MSDASQL)."

In other words, you can't use ODBC.

Is there a native OLE DB Provider for dBASE? Microsoft's web site mentions
one for FoxPro, which might work for you, but they don't mention where to
get it (other than buying Visual FoxPro).

There might also be a clunky way of getting to your data through Jet, since
Access can link to ODBC databases. That's not something I've done before, so
I can't even guess if it would work.

Article that says MSDASQL doesn't work:
http://msdn.microsoft.com/library/en-us/cpguidnf/html/cpconadonetproviders.a
sp?frame=true

Article that mentions Visual FoxPro OLE DB Provider:
http://msdn.microsoft.com/library/en-us/fox7help/html/dggrfOLEDBProviderforV
isualFoxPro.asp?frame=true

Nate


"Burhan H. Afandi" <baf...@hotmail.com> wrote in message

news:uMmDShsDBHA.1876@tkmsftngp07...

Ryan Farley

unread,
Jul 18, 2001, 7:17:20 PM7/18/01
to
Well, this is using beta2, so you'll have to translate it back to beta1 -
although that shouldn't be hard since all you really need is the connection
string. You can use the Jet provider as long as you set the extended
properties to dBase IV (or it could be dBase III, dBase V, or whatever.)

//dBase tables located in 'C:\Data\Common' is this example
OleDbConnection conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\\Data\\Common;Extended Properties=dBase IV;");

//a dBase file named Contact1.dbf is located in the dir specified above
OleDbCommand cmd = new OleDbCommand("SELECT * FROM CONTACT1", conn);

You can go from there.
--

Ryan Farley
Lead Application Developer
Customer FX Corporation

"Nathan Silva" <nat...@usa.net> wrote in message
news:u#S60n9DBHA.1616@tkmsftngp02...

Nathan Silva

unread,
Jul 18, 2001, 8:28:00 PM7/18/01
to
Cool. I also found out that you *can* use ODBC from .NET. You have to
install another component, ODBC.NET beta 1. It is found at:

http://www.microsoft.com/downloads/release.asp?ReleaseID=31125

But it won't work for Mr. Afandi because it requires .NET Framework SDK Beta
2.

Nate


"Ryan Farley" <ryan....@removethisnospam.customerfx.com> wrote in message
news:eNKKr$9DBHA.1400@tkmsftngp05...

Burhan H. Afandi

unread,
Jul 19, 2001, 9:09:22 AM7/19/01
to


Using the following code, I can read the database; I can even make changes
to it in the memory, but for whatever reason the database remains unchanged.
There are no errors reported, everything seems to work fine but when I check
the database to see if it has changed, everything looks untouched.

Here is the code:

//dBase tables located in 'C:\Data\Common' is this example

ADOConnection conn = new
ADOConnection("Provider=MSDASQL;DataSource=C:\\Data\\Common;driver=Microsoft
dBase Driver (*.dbf)");

//a dBase file named Contact1.dbf is located in the dir specified above

DataSet dataSet=new DataSet();

dataSet.Tables.Add( "Contact1");

ADODataSetCommand dsc=new ADODataSetCommand(@"SELECT * FROM
c:\data\Common\Contact1",conn);

dsc.FillDataSet(dataSet,"Contact1");

try

{

conn.Open();

for(int i=0;i<dataSet.Tables[0].Rows.Count;i++)

{

dataSet.Tables["
Contact1"].Rows[i][0]=(double)dataSet.Tables[0].Rows[i][0]/2;

}

dataSet.Tables[0].DataSet.Update(null);

dataSet.Tables[0].AcceptChanges();

}

catch(Exception e1)

{

System.WinForms.MessageBox.Show(e1.ToString());

}

finally

{

conn.Close();


}

"Ryan Farley" <ryan....@removethisnospam.customerfx.com> wrote in message
news:eNKKr$9DBHA.1400@tkmsftngp05...

Jamie Macleod

unread,
Jul 19, 2001, 3:22:37 PM7/19/01
to
Extended Systems has a free OLE DB driver for DBF files using CDX/NTX
indexes. Maybe this will give you what you need.
www.advantagedatabase.com.

Jamie


"Burhan H. Afandi" <baf...@hotmail.com> wrote in message

news:OQjC6PFEBHA.1268@tkmsftngp07...

Burhan H. Afandi

unread,
Jul 19, 2001, 6:14:58 PM7/19/01
to
i couldn't find that driver and i am not sure if it can help.

"Jamie Macleod" <bubam...@yahoo.com> wrote in message
news:OAMSPgIEBHA.1348@tkmsftngp02...

0 new messages