如何使用 C# 创建 .dbf 文件?
我正在尝试使用此方法进行选择,并且效果很好
string str =
"SELECT * FROM FREE RIGHT JOIN TestTest ON FREE.DOCNO = TestTest.DOCNO";
DataTable dt = new DataTable();
OdbcDataAdapter da = new OdbcDataAdapter(str, odbconn);
da.Fill(dt);
我正在尝试使用此方法创建 .dbf 并得到此 OdbcException :
string str0 = "Create Table Persons (Name char(50), City char(50), Phone char(20), Zip decimal(5))";
OdbcCommand cmd = new OdbcCommand(str0, odbconn);
cmd.ExecuteNonQuery();
错误 [42000] [Microsoft][ODBC dBase 驱动程序] 字段定义中存在语法错误。
I am trying this to make a select and it works just fine
string str =
"SELECT * FROM FREE RIGHT JOIN TestTest ON FREE.DOCNO = TestTest.DOCNO";
DataTable dt = new DataTable();
OdbcDataAdapter da = new OdbcDataAdapter(str, odbconn);
da.Fill(dt);
I am trying this to create a .dbf and i get this OdbcException :
string str0 = "Create Table Persons (Name char(50), City char(50), Phone char(20), Zip decimal(5))";
OdbcCommand cmd = new OdbcCommand(str0, odbconn);
cmd.ExecuteNonQuery();
ERROR [42000] [Microsoft][ODBC dBase Driver] Syntax error in field definition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是由
Zip Decimal(5)
引起的,因为 ODBC dBase 驱动程序不喜欢它。在我快速谷歌之后,我无法想出它可以容忍的语法。如果您使用 OleDb 提供程序,它确实会非常愉快地接受它,如下所示:但有一个问题:您确定要将 Zip 列创建为小数吗?我不是美国居民,我对这些信息不是 100% 有信心,但是,根据维基百科 邮政编码可以以
0
开头。将它们存储为数字数据类型将不允许您准确地表示它。我通过 ODBC 创建表的代码:
Your problem is caused by
Zip decimal(5)
, as the ODBC dBase driver doesn't like it. Off the top of my head, and after a quick google, I couldn't come up with a syntax it would tolerate. It does accept it quite merrily if you use the OleDb provider instead, as follows:One question though: Are you sure that you want to create the Zip column as a decimal? Not being a US resident I'm not 100% confident on this information, but, according to Wikipedia ZIP codes can start with a
0
. Storing them as a numeric datatype won't allow you to accurately represent that.My code for creating the table via ODBC:
使用 vfpoledb 提供程序和字段类型
NUMERIC
而不是DECIMAL
。Use vfpoledb provider and field type
NUMERIC
instead ofDECIMAL
.