Barts007


I¡¯m trying to create a new free table, which is a dbf file in FoxPro, but I do not understand where is it saved on the drive.

Plus, I¡¯m getting a n error: ¡°Invalid path or file name.¡±

I¡¯m using VB.NET,:

SetConnectionString = "Provider=vfpoledb.1;Data Source=C:\VFP\myFile.dbf"

¡­.

ExecuteNonQuery("CREATE TABLE 'C:\VFP\myFile.dbf' FREE (yr INT)")

What's wrong

Thanks




Re: CREATE TABLE, but where is it saved on the drive?!

MarciaAkins


Barts007 wrote:

I¡¯m trying to create a new free table, which is a dbf file in FoxPro, but I do not understand where is it saved on the drive.

Plus, I¡¯m getting a n error: ¡°Invalid path or file name.¡±

My best guess is that you do not have a folder called VFP on your C drive.







Re: CREATE TABLE, but where is it saved on the drive?!

Naomi Nosonovsky

If you don't have a table, when why this is your connection string






Re: CREATE TABLE, but where is it saved on the drive?!

dni

If is really saved, you may check with CURDIR() before save to find the current folder ....and where file is saved.






Re: CREATE TABLE, but where is it saved on the drive?!

Barts007

Naomi,

You are right, I do not know how to write the connection string for this situation, when the file does not yet exist, but has to be created.

However, I also tried this:

SetConnectionString = "Provider=vfpoledb.1;"

and got error: "Feature is not available."

Any ideas





Re: CREATE TABLE, but where is it saved on the drive?!

Barts007

Naomi, the folder VFP does exist on my C.

dni, the file is not saved anywhere, I¡¯m actually getting an error: ¡°Invalid path or file name.¡±





Re: CREATE TABLE, but where is it saved on the drive?!

CetinBasoz

setconnectionstring = "Provider=vfpoledb;Data Source=c:\VFP"

...

ExecuteNonQuery("create table myFile free (yr i)")

Would create that in c:\vfp

or:

setconnectionstring = "Provider=vfpoledb;Data Source=c:\VFP"

...

ExecuteNonQuery("create table ('c:\ThisIsTheFolderIwant\myFile') free (yr i)")

would create that in c:\ThisIsTheFolderIwant





Re: CREATE TABLE, but where is it saved on the drive?!

Barts007

Life is beautiful again, thanks!




Re: CREATE TABLE, but where is it saved on the drive?!

CetinBasoz

You can convert this sample to VB.Net (assumed c:\temp and c:\My Folder exist):

Code Snippet

using System;
using System.Data;
using System.Data.OleDb;
class test
{
static void Main()
{
string strCon = @"Provider=VFPOLEDB;Data Source=c:\temp";
OleDbConnection cn = new OleDbConnection(strCon) ;
cn.Open();
OleDbCommand cmdCreateTable = new OleDbCommand("create table myNetTable free (f1 i)",cn);
cmdCreateTable.ExecuteNonQuery();
cmdCreateTable.CommandText = @"create table ('c:\My Folder\myNettable') free (f1 i)";
cmdCreateTable.ExecuteNonQuery();
cn.Close();
}
}





Re: CREATE TABLE, but where is it saved on the drive?!

Barts007

The more I work on this issue the more confused I get!

I did manage to create my free table (dbf file). But, then if I open the file for browsing in FP6I see that the columns created are not in the correct order, not in the order that I wrote them in the SQL CREATE TABLE statement.

However, if select Table Designer menu in FP6, the fields are in the correct order! What gives




Re: CREATE TABLE, but where is it saved on the drive?!

Naomi Nosonovsky

Which VFP version you're using

In any case, you may want to type

MODIFY STRUCTURE and you will see all the fields and their order.

If you do BROWSE command and you use resource file (set resource is on) then the last way you looked at the file may be saved. You probably re-arranged columns orders.

You may type BROWSE NORMAL to make sure you're looking at the table in its natural fields' order.





Re: CREATE TABLE, but where is it saved on the drive?!

CetinBasoz

Display may be different then actual physical order (even the field names) based on a few factors like having a dbc or not, browse last, browse preference etc.

You can check the actual order:

Code Snippet

use myTable

for ix=1 to fcount()

m.ix, field(m.ix)

endfor

However in any case, you shouldn't write code that depends on physical order of fields. That is a dangerous thing to do IMHO. If you need this for something like SqlBulkCopy column mappings, you can get the ordinals from DataReader.