1、执行查询操作:(ExecuteReader方法)
string myConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = "+Server.MapPath("~/") +"App_Data/access.mdb"; //使用相对路径连接数据库
string mySelectQuery = "select * from login where userName ='lwjj'";//查询语句
OleDbConnection myConnection = new OleDbConnection(myConnectionString);
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
myConnection.Open();
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
while(myReader.Read())
{
Console.WriteLine(myReader.GetString(0));
//GetString(0,1,2....)
}
myReader.Close();
{
string myConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = "+Server.MapPath("~/") +"App_Data/IPTJ.mdb"; //Data Source = 数据库绝对路径