以下是我创建 DBF 文件= ANSI 文件的方式:
var path = @"Z:\";
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=dBASE IV;User ID=Admin;Password=;";
OleDbConnection con = new OleDbConnection(constr);
con.Open();
string CreateTableK =
"CREATE TABLE TEST (ID char(50),NAME char(50),FAMILY char(50))";
OleDbCommand cmdCreateTable = new OleDbCommand(CreateTableK, con);
cmdCreateTable.ExecuteNonQuery();
string MyInsert =
"insert into TEST ( ID, NAME, FAMILY ) values ( ?, ?, ? )";
OleDbCommand cmd3 = new OleDbCommand(MyInsert, con);
cmd3.Parameters.AddWithValue("parmSlot1", "22");
cmd3.Parameters.AddWithValue("parmSlot2", "Oliver");
cmd3.Parameters.AddWithValue("parmSlot3", "¢ُںُ");
cmd3.ExecuteNonQuery();
MessageBox.Show("done");
我删除所有使用...以澄清我在说什么
现在打开驱动器TEST.DBF
中的Z:\
文件,看看parmSlot3是如何更改的
我希望{DB}文件中没有"¢ُںُ"
字符串。{
如何定义DBF文件的编码或如何完成这项工作?
var path = @"Z:\";
var fileName = "TEST.DBF";
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=dBASE IV;";
using (OleDbConnection con = new OleDbConnection(constr))
{
var sql = "select * from " + fileName;
OleDbCommand cmd = new OleDbCommand(sql, con);
con.Open();
OleDbDataReader reader = cmd.ExecuteReader();
string value = "";
if (!reader.HasRows)
{
//BLO BLO BLO
}
else
{
while (reader.Read())
{
value = reader.GetString(2);
break;
}
}
}
但在这些代码后,值与"¢ُںُ"
字符串不同。
如何获得"¢ُںُ"
字符串而不是"تُاُ"
?