3

我有一个要执行查询的 dbf 文件。这是我的代码(.net 4.0,C# Windows 窗体):

oconn.ConnectionString = "Provider=vfpoledb.1;Data Source=" + path + ";Collating Sequence=machine";
oconn.Open();
OleDbCommand ocmd = oconn.CreateCommand();
string na = TBNazwaKonta.Text.Replace("\n","");
na = na.Replace("\r","") ;
string ks2 = ks.Replace("\n","");
ks2 = ks2.Replace("\r", "");
string zapytanie = @"insert into " + path + " (rk, Na,Ks,Ss,So,Wyr,Bw,Bm,Ow,Om,Wm,Mm,Pm,Pw,Ks1,Ks2,Ks3,Ks4,Llx,Wn01,Ma01,L01,Wn02,Ma02,L02,Wn03,Ma03,L03,Wn04,Ma04,L04,Wn05,Ma05,L05,Wn06,Ma06,L06,Wn07,Ma07,L07,Wn08,Ma08,L08,Wn09,Ma09,L09,Wn10,Ma10,L10,Wn11,Ma11,L11,Wn12,Ma12,L12) values (0,'Z-Dz PROD.OPAKOWAŃKIEWICZA 108   38-200 ', '200 02 000212',0,0,'',0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,'','','','',0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0,0.0,0.0,0)";
ocmd.CommandText = zapytanie;
ocmd.ExecuteNonQuery();
oconn.Close();

连接很好,插入查询也很好,但我想知道为什么这个 dbf 不接受空值。

我在哪里可以检查 dbf 是否接受空值?当我使用程序读取 dbfs 并执行查询时,dbf 接受 null。它仅在我使用 ado.net 时才接受。感谢您帮助解决我的问题

4

2 回答 2

4

您可以创建一个新命令并在插入之前执行它。

OleDbCommand dbCmdNull = oconn.CreateCommand();
dbCmdNull.CommandText = "SET NULL OFF";
dbCmdNull.ExecuteNonQuery();
于 2012-06-28T07:37:39.197 回答
1

您可以将列设置为不接受空值。

如果您使用的是visual foxpro,请打开您的dbf,转到查看> 表设计器您将看到列列表,最后一列指示它是否接受空值。

那里有一个 Null 按钮。取消选中,您的列将不接受空值。

这将确保您不会写空值。但是如果有空值,你就在某处写它们。您将不得不修复那段代码。

于 2012-06-28T07:48:42.163 回答