1
votes

I need to change the width of a .dbf char field but if someone knows how to create it I think I could adapt.

protected void CreateDbf()
    {
        using (var dBaseConnection = new OdbcConnection(@"Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;Dbq=C:\users\desenv\desktop"))
        {
            dBaseConnection.Open();

            string str0 = "Create Table FUNCTES (CODCRA char(400), REGFUN char(6), NOMFUN char(30), DTANAS date, STATUS logical, DESCRI memo)";
            var cmd = new OdbcCommand(str0, dBaseConnection);
            cmd.ExecuteNonQuery();

            dBaseConnection.Close();
        }
    }

And it gives me this ERROR:

ERROR [42000] [Microsoft][Driver ODBC para dBase] O tamanho do campo 'CODCRA' é muito longo.

Translating the last part .. "The size of the field 'CODCRA' is too large."

I've already tried to use other Providers and Drivers to generate the file but it didn't work.

So if someone could help me I would be very pleased.

I know that this is possible in Clipper by using the function DBCREATE()

1
I don't recommend you create such a long-sized field in dbf anyway, because later you probably will get a problem reading data from it. See stackoverflow.com/questions/754948/dbf-large-char-field as example of problems can occur.Andy Korneyev
Yes, I saw the problem that it can occur but reading the file it's not a big deal right now, the thing is, I need it this way because here in the company there is a code that do this job(create with more than 254 of width) in Clipper but it doesn't work in 64 bits machines and C# is the only choice. =( .. Thanks about your commentEng comp

1 Answers

0
votes

It is failing on your column of 400 characters... dbase/vfp tables only allow 255 characters for a column width.. After that, you have to use a "memo" field which is free-form and can hold text or binary.

The only other possibility that I can think of looking into is SyBase's Database-Advantage either Server or LocalServer products. They work with .DBFs but allow extending them while leaving the data in somewhat original .dbf style format. That may be an option for you a link for Sybase Advantage Database Server but they also have a "local server" version but can't find that download link. You might have to dig into that a bit... but the database server has a free 30-day trial.