access数据库
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
/* string connstr = "server=(local);initial catalog=shiji;user id=sa;pwd=123";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText ="select * from shi";
SqlDataReader read = cmd.ExecuteReader();
*/
OleDbConnection conn = new OleDbConnection( );
string connstr = "Provider=Microsoft.Jet.OLEDB.4.0;User id=Admin;Jet OLEDB:database Password=1;data source=";
connstr += @"tyg.mdb";
conn.ConnectionString = connstr;
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from shi";
OleDbDataReader read = cmd.ExecuteReader();
while (read.Read())
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}", read.GetInt32(0), read.GetString(1), read.GetString(2), read.GetString(3));
}
Console.ReadKey();
read.Close();
conn.Close();
}
}
}