如何向 .DBF 文件添加列?
我遇到的问题之一是,我认为该表没有名称...它只是一个 .dbf 文件
所以我一直在尝试这样做:
public void SQLAlter(string dbffile, string ColumnName )
{
//dbffile is "C:\MAPS\WASHINGTON\TLG_ROADS_L.DBF"
//ColumnName is "State"
if (File.Exists(dbffile))
{
System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();
conn.ConnectionString = @"DSN=dBase Files";
conn.Open();
System.Data.Odbc.OdbcCommand comm = new System.Data.Odbc.OdbcCommand();
comm.CommandText = "ALTER TABLE " + dbffile + " ADD COLUMN " + ColumnName + " VARCHAR(1024)";
comm.ExecuteNonQuery();
}
}
错误是:
基{System.Data.Common.DbException} = {“错误[42S02] [Microsoft][ODBC dBASE 驱动程序] 找不到表或约束。"}
One of the issues I have is that, I don't think the table has a name... its just a .dbf file
So I've been trying this:
public void SQLAlter(string dbffile, string ColumnName )
{
//dbffile is "C:\MAPS\WASHINGTON\TLG_ROADS_L.DBF"
//ColumnName is "State"
if (File.Exists(dbffile))
{
System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();
conn.ConnectionString = @"DSN=dBase Files";
conn.Open();
System.Data.Odbc.OdbcCommand comm = new System.Data.Odbc.OdbcCommand();
comm.CommandText = "ALTER TABLE " + dbffile + " ADD COLUMN " + ColumnName + " VARCHAR(1024)";
comm.ExecuteNonQuery();
}
}
The error is :
base {System.Data.Common.DbException} = {"ERROR [42S02]
[Microsoft][ODBC dBASE Driver] Cannot find table or constraint."}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信表名应该是文件名,连接字符串应该指向包含 dbf 文件的文件夹。
检查connectionstrings.com:http://connectionstrings.com/dbf-foxpro
I believe the table name is supposed to be the filename, and the connection string should point to the folder containing the dbf file.
Check connectionstrings.com: http://connectionstrings.com/dbf-foxpro
这实际上是正确的语法
,但是如果您的文件名超过 8 个字符,它将找不到它。尽管我尝试使用适当长度的文件名,但“包含数据的表不支持该操作”。
各种互联网链接似乎表明必须创建一个新表,并复制所有字段。
This is actually the correct syntax
However if your filename is longer than 8 characters it will not find it. Even though I tried it will an appropriate length file name, the "Operation [is] not supported on a table that contains data."
Various Internet links seem to indicate that one has to create a new table, and copy all the fields over.
尝试另一个提供商。
它与 Visual Foxpro Provider 对我有用
conn.ConnectionString = @"Provider=VFPOLEDB.1; 数据源=Themes.dbf" + @"\;扩展属性=dBase IV";
如果您的计算机上未安装驱动程序,您可以在此处获取:
http://www.microsoft.com/en-us/download /details.aspx?id=14839
Try another Provider.
It worked for me with the Visual Foxpro Provider
conn.ConnectionString = @"Provider=VFPOLEDB.1; Data Source=Themes.dbf" + @"\;Extended Properties=dBase IV";
If the driver is not installed on your machine, you get it here :
http://www.microsoft.com/en-us/download/details.aspx?id=14839