我使用下面的代码创建一个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();
}
答案 0 :(得分: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);
答案 1 :(得分: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提供者: