1

我使用下面的代码创建了一个 dbf 文件并填充它,一切正常。问题是文件名被截断为最多 8 个字符。知道为什么或如何保持全名吗?

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+";Extended Properties=dBase IV";
OleDbConnection connection = new OleDbConnection(connectionString);
        connection.Open();
cmd.CommandText = @"CREATE TABLE calendfull(
                                date1 datetime ,
                                day1 int ,
                                month1 int ,
                                year1 int ,
                                dow int ,
                                endmonth int  
                                )";

            cmd.ExecuteNonQuery();

  foreach (DataRow row in calend.Rows)
            {
                day = Convert.ToInt32(row["day"]);
                year = Convert.ToInt32(row["year"]);
                month = Convert.ToInt32(row["month"]);
                dow = Convert.ToInt32(row["dow"]);
                endmonth = Convert.ToInt32(row["endmonth"]);
                date1 = Convert.ToDateTime(row["date1"]);

                cmd.CommandText = @"insert into calendFull  values ('" + date1 + "'," + day + "," + month + "," + year + "," + dow + "," + endmonth + ")";
                cmd.ExecuteNonQuery();
            }
4

2 回答 2

1

DBF 文件名遵循 8.3 命名规范,因此名称不能超过 8 个字符。

但是等等,我已经看到一些名称大于 8 个字符的 dbf 文件。

是的,这是允许的,但是当您在命令提示符中查看时,它们的实际名称类似于文件名。例如largef~1

那么我该如何阅读它们呢?您应该使用kernel32.dll获取他们的简称

这是代码:

    public string GetShortFileName(string fileDirectory, string fileNameWithExtension)
    {
        StringBuilder temp = new StringBuilder(255);

        string path = System.IO.Path.Combine(fileDirectory, fileNameWithExtension);

        int n = GetShortPathName(path, temp, 255);

        if (n == 0)
            throw new NotImplementedException();

        string extension = System.IO.Path.GetExtension(path);

        return ((temp.ToString().Split('\\')).Last()).ToLower();//.Replace(extension, string.Empty);
    }

    [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
            public static extern int GetShortPathName(
        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]    
        string path,
        [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]    
        StringBuilder shortPath,
        int shortPathLength);
于 2013-04-02T09:53:58.457 回答
0
        const string connectionString = @"Provider = vfpoledb; Data Source = {0}; Collating Sequence = general;";
        OleDbConnection conn = new OleDbConnection(string.Format(connectionString, dirName));
        conn.Open();
        OleDbCommand cmd = new OleDbCommand(string.Format("select * from {0}", fileName), conn)

更改 oledb 提供程序:

使用 Microsoft OLE DB Provider for Visual FoxPro 9.0

于 2016-07-15T12:11:28.680 回答