using System;
using System.Data;
using System.Data.SqlClIEnt;
using System.Data.OleDb;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要說明。
/// </summary>
class Class1
{
/// <summary>
/// 應用程序的主入口點。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//以下是連接Access
OleDbConnection dbconn=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:\a.mdb");
dbconn.Open();
//OleDbCommand cmd=new OleDbCommand("select * from test1",dbconn);
OleDbCommand cmd=dbconn.CreateCommand();
cmd.CommandText="select * from test1";
cmd.CommandType=CommandType.Text;
OleDbDataReader reader=cmd.ExecuteReader();
//以下是連接SQL2000
/*SqlConnection conn=new SqlConnection("server=localhost;Initial catalog=NorthWind;user ID=sa;passWord=;");
conn.Open();
SqlCommand cmd=conn.CreateCommand();
cmd.CommandText="select * from Customers";
cmd.CommandType=CommandType.Text;
SqlDataReader reader=cmd.ExecuteReader(CommandBehavior.CloseConnection);*/
string output;
while(reader.Read())
{
output=string.Format("custormer {0}:{1} works for {2}",reader.GetString(1),reader.GetString(2),reader.GetString(3));
Console.WriteLine(output);
}
}
}
}