oledb连接access数据库示例
using system;
using system.collections.generic;
using system.text;
using system.data;
using system.data.oledb;
namespace consoleapplication1
{
class program
{
static void main(string[] args)
{
oledbconnection conn = new oledbconnection();
oledbcommand comm = new oledbcommand();
oledbdatareader dr=null;
conn.connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" + system.environment.currentdirectory + "\\simplenews.mdb";
comm.connection = conn;
comm.commandtext = "select * from [login]";
try
{
conn.open();
dr = comm.executereader();
while (dr.read())
{
for (int i = 0; i < dr.fieldcount; i++)
console.write(dr.getvalue(i) + " ");
console.writeline("");
//dr.close();
}
dr.close();
}
catch (exception err)
{
console.writeline(err.message);
}
finally
{
comm = null;
conn.close();
comm = null;
console.readkey();
}
}
}
}