我有这个代码可以快速搜索数据库。
它在sqlCE上运行良好。
现在我需要翻译它将适用于Access 2007
怎么做?
public bool LOOK()
{
Tmp = "";
MAK = "";
DES = "";
Cmd.CommandType = CommandType.TableDirect;
Cmd.CommandText = "BarcodeTbl";
Cmd.IndexName = "Barcode";
Cmd.SetRange(DbRangeOptions.Match, new object[] { txtYad.Text }, null);
SqlCeDataReader read = Cmd.ExecuteReader();
while (read.Read())
{
Tmp = read[2].ToString();
MAK = read[0].ToString();
DES = read[1].ToString();
}
read.Dispose();
if (Tmp == "")
{
return false;
}
else
{
txtYad.Text = DES;
return true;
}
}
提前谢谢
答案 0 :(得分:2)
您需要使用System.Data.OleDb namespace中的类,例如OleDbDataReader
,OleDbCommand
等。
顺便说一句,以下内容:
SqlCeDataReader read = Cmd.ExecuteReader();
while (read.Read())
{
Tmp = read[2].ToString();
MAK = read[0].ToString();
DES = read[1].ToString();
}
read.Dispose();
可写得更好:
using(SqlCeDataReader read = Cmd.ExecuteReader())
{
while (read.Read())
{
Tmp = read[2].ToString();
MAK = read[0].ToString();
DES = read[1].ToString();
}
} // .Dispose() is called automatically here