oledbdatareader的用法!
如何用oledbdatareader读取单个的记录? --------------------编程问答-------------------- 与其他 DataReader 无异 --------------------编程问答-------------------- OleDataReader dr = cmd.ExecuteDataReader();if(dr.Read()) {
object val1 = dr["Field1"];
// object val2 = dr["Field2"];
// ...
} --------------------编程问答-------------------- sorry ->
OleDbDataReader dr = cmd.ExecuteReader();
另,假如,单行单列,应该使用 ExecuteScalar();
object o = cmd.ExecuteScalar();
if(o != null) {
// ...
}
--------------------编程问答-------------------- 来晚了 答的不错 --------------------编程问答-------------------- using(OleDbConnection connection = new OleDbConnection(""))
{
OleDbCommand cmd = new OleDbCommand(strSQL, connection);
connection.Open();
OleDbDataReader myReader = cmd.ExecuteReader();
while(myReader.Read())
{}
} --------------------编程问答-------------------- string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=product.mdb";
OleDbConnection odcConnection = new OleDbConnection(strConn); //2、打开连接 C#操作Access之按列读取mdb
odcConnection.Open(); //建立SQL查询
OleDbCommand odCommand = odcConnection.CreateCommand();
odCommand.CommandText = "select Field1 from Table1"; //建立读取 C#操作Access之按列读取mdb
OleDbDataReader odrReader = odCommand.ExecuteReader();
while (odrReader.Read())
{
if(odrReader["Field1"]!=DBNull.Value;
{
string str=odrReader["Field1"].ToString();
}
}
odrReader.Close();
odcConnection.Close();
补充:.NET技术 , ASP.NET