隨着最後把這個問題休息了希望:
它不要緊什麼Jet數據庫引擎使用爲Yes/True
和No/False
其內部表示。我們得到一個System.Boolean
值。
在Access中,Yes/No
字段爲Yes/True
或No/False
。 NULL
的值是No/False
。
測試數據:
測試代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
namespace oleDbTest
{
class Program
{
static void Main(string[] args)
{
string myConnectionString;
myConnectionString =
@"Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data Source=C:\Users\Public\Database1.accdb;";
using (var con = new OleDbConnection())
{
con.ConnectionString = myConnectionString;
con.Open();
using (var cmd = new OleDbCommand())
{
// just to be sure, let's force one of the values to Null
cmd.Connection = con;
cmd.CommandText =
"UPDATE YesNoTable SET YesNoField = NULL " +
"WHERE Description = 'Null'";
cmd.ExecuteNonQuery();
}
using (var cmd = new OleDbCommand())
{
cmd.Connection = con;
cmd.CommandText =
"SELECT ID, YesNoField, Description FROM YesNoTable";
OleDbDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(String.Format("Row {0}:", rdr["ID"]));
bool boolValue = Convert.ToBoolean(rdr["YesNoField"]);
Console.WriteLine(String.Format(" Description is: {0}", rdr["Description"]));
Console.WriteLine(String.Format(" Return type is: {0}", rdr["YesNoField"].GetType()));
Console.WriteLine(String.Format(" raw value is: {0}", rdr["YesNoField"]));
Console.WriteLine(String.Format(" boolValue is: {0}", boolValue));
Console.WriteLine();
}
}
con.Close();
}
Console.WriteLine("Done.");
}
}
}
結果:
Row 1:
Description is: Yes
Return type is: System.Boolean
raw value is: True
boolValue is: True
Row 2:
Description is: No
Return type is: System.Boolean
raw value is: False
boolValue is: False
Row 3:
Description is: Null
Return type is: System.Boolean
raw value is: False
boolValue is: False
Done.
它是布爾值並保持布爾值。 – adatapost
你能否展示你所嘗試過的(你的代碼更具體)? –
向我們展示一些代碼。 – gabsferreira