invalid path error while accessing FOXPRO table from c#

A

abhayjoukani

HI All,
i have a problem accessing a DBF file from c#. this is the code i have
specified

string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\mmyyyy.dbf;Extended Properties=DBASE IV;";
OleDbConnection objConnn = new OleDbConnection();
objConnn.ConnectionString = strConnection;
try
{
objConnn.Open();
}
catch(Exception eee)
{
MessageBox.Show(eee.ToString());
}
objConnn.Close();


it says

System.Data.OleDb.OleDbException: 'c:\mmyyyy.dbf' is not a valid path.
Make sure that the path name is spelled correctly and that you are
connected to the server on which the file resides.
at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
at System.Data.OleDb.OleDbConnection.InitializeProvider()
at System.Data.OleDb.OleDbConnection.Open()
at WindowsApplication2.Form1.button3_Click(Object sender, EventArgs
e) in d:\documents and settings\administrator\my documents\visual
studio projects\windowsapplication2\form1.cs:line 426


it is strange because i have been connection to the local computer not
a networkd one and + i have been accessing this since past few days
without a problem

i have installed Microsoft's oledb drivers for foxpro + MDAC


PN :- i have tries this connection string also
"Provider=VFPOLEDB.1;Data Source="C:\mmyyyy.dbf;"

thanks,
abhay.
 
C

Cindy Winegarden

Hi Abhay,

I recommend that you use the OLE DB data provider for FoxPro and Visual
FoxPro.

There are two formats that the connection string should take, depending on
what data you have.

For FoxPro "free" tables use just the path to the directory where the DBFs
are: "Provider=VFPOLEDB.1;Data Source=C:\Temp;" Note that the Data Source is
not in quotes it's delimited bye the equal sign and the semicolon. When you
want to work with a specific table you'll specify it in your SQL string:
strSQL = "Select * From SomeTable" (Table is C:\Temp\SomeTable.dbf)

For Visual FoxPro tables that belong to a "Database Container" you need to
specify the DBC in the connection string: "Provider=VFPOLEDB.1;Data
Source=C:\Temp\MyDBC.dbc;" If a DBC file is present with the DBFs then use
this format, otherwise use the free table format. Again refer to a specific
table in your SQL command: strSQL = "Select * From SomeTable"


--
Cindy Winegarden MCSD, Microsoft Most Valuable Professional
(e-mail address removed)


string strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\mmyyyy.dbf;Extended Properties=DBASE IV;";
 
A

Abhay

Cindy said:
Hi Abhay,

I recommend that you use the OLE DB data provider for FoxPro and Visual
FoxPro.

There are two formats that the connection string should take, depending on
what data you have.

For FoxPro "free" tables use just the path to the directory where the DBFs
are: "Provider=VFPOLEDB.1;Data Source=C:\Temp;" Note that the Data Source is
not in quotes it's delimited bye the equal sign and the semicolon. When you
want to work with a specific table you'll specify it in your SQL string:
strSQL = "Select * From SomeTable" (Table is C:\Temp\SomeTable.dbf)

For Visual FoxPro tables that belong to a "Database Container" you need to
specify the DBC in the connection string: "Provider=VFPOLEDB.1;Data
Source=C:\Temp\MyDBC.dbc;" If a DBC file is present with the DBFs then use
this format, otherwise use the free table format. Again refer to a specific
table in your SQL command: strSQL = "Select * From SomeTable"


thank you Cindy, you are a life saver :). i realised my mistake!!
thought having said this i have another problem! i hope u would help me
out!

i need to fill a (free) table which has the following structure

field_name width dec type nulls
EMP_NO 7 numeric no
NAME 30 char no
FATHER 30 char no
BIRTHDAY 8 Date no
SEX 1 char no
APPOINTED 8 Date no
xxx 10 numeric no
xxx 10 numeric no
xxx 10 numeric no
xxx 10 2 numeric no
xxx 10 2 numeric no
xxx 10 2 numeric no
xxx 7 numeric no

total width = 162


NOW i know this is a stupid ? to ask as the structure does not allow
null values!! but i want to store null values for every collumn !!

could u give me a FOXPRO command to create such table which also accept
null values! and is the same replica of the rest of the structure <<
DBASE IV offcourse

I tried to create such a table with foxpro 6.0 but it seems to change
the TOTAL WIDTH from 162 to 169



PN :- i need such a table in which i could insert null values in all
columns!
 
C

Cindy Winegarden

Hi Abhay,

You're really better off creating a new thread for a totally different
question.

You mention Dbase IV. FoxPro tables were not capable of storing null values
until Visual FoxPro 3. VFP tables with nulls are not compatible with things
that require the older-format such as when you open a Fox2.x table in Excel.
Even though these older format tables cannot store nulls they can store
"empty" values.

I'm not sure why you are so concerned about the total length of the table.

To create a Visual FoxPro table that allows null values use SQL like this:
"Create Table MyTable (EmpNo N(7) Null, Name C(30) Null, ...)" An added
advantage of Visual FoxPro tables is that they allow an Integer data type
which should be appropriate for your EmpNo field. An advantage is that
Numeric values are actually stored internally as characters, taking up more
space than Integers, for example.
 
A

Abhay

Cindy said:
Hi Abhay,

You're really better off creating a new thread for a totally different
question.

You mention Dbase IV. FoxPro tables were not capable of storing null values
until Visual FoxPro 3. VFP tables with nulls are not compatible with things
that require the older-format such as when you open a Fox2.x table in Excel.
Even though these older format tables cannot store nulls they can store
"empty" values.

I'm not sure why you are so concerned about the total length of the table.

To create a Visual FoxPro table that allows null values use SQL like this:
"Create Table MyTable (EmpNo N(7) Null, Name C(30) Null, ...)" An added
advantage of Visual FoxPro tables is that they allow an Integer data type
which should be appropriate for your EmpNo field. An advantage is that
Numeric values are actually stored internally as characters, taking up more
space than Integers, for example.

actully im fomatting some data givin to me in a excel sheet and
transforming it into a foxpro (DBASE IV) table and sending it to a
program which is made in forpro 2.6 for a import

cindy i saw u mentioned that "Even though these older format tables
cannot store nulls they can store empty values"

i need to store empty value columns!! im using c# and when i go to
store nothing it says a value is required!! what do u think is the
problem??

these are the statements that i run

objNewDataRow["EMP_NO"] = objOldDataRow["EMP_NO"];
objNewDataRow["NAME"] = objOldDataRow["NAME"];
objNewDataRow["FATHER"] = objOldDataRow["FATHER"];
//objNewDataRow["BIRTHDAY"] = DateTime.Now; << COMMENTED ROW
objNewDataRow["SEX"] = "";

......
...
...
objAdapter.Update(objdataSet);


when i dont comment the BIRTHDAY its fine! the program works (though im
inserting current date into the birthday column)

but when i comment it and try to store empty value

System.Data.OleDb.OleDbException: Field BIRTHDAY does not accept null
values.
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows,
DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String
srcTable)
at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
at WindowsApplication2.Form1.button3_Click(Object sender, EventArgs
e) in d:\documents and settings\administrator\my documents\visual
studio projects\windowsapplication2\form1.cs:line 474


thanks,
abhay.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top