OLEDB ACCESS
public void AccessConn()
{
        string strConnection = @"Provider=Microsoft.Jet.OleDb.4.0;";
        strConnection += @"Data Source=C:\DB.mdb";

        OleDbConnection DBConn;
        OleDbCommand DBCommand;
        OleDbDataReader DBReader;

        try
        {
                DBConn = new OleDbConnection(strConnection);
                DBConn.Open();
                DBCommand = DBConn.CreateCommand();
                DBCommand.CommandText = "select A, B, C, D from TestTable";
                DBReader = DBCommand.ExecuteReader();

                int i = 1;
                while (DBReader.Read())
                {
                        System.Console.WriteLine("============================================================");
                        System.Console.WriteLine("No" + i);
                        System.Console.WriteLine(DBReader.GetName(0).ToString() + "=" + DBReader.GetValue(0).ToString());
                        System.Console.WriteLine(DBReader.GetName(1).ToString() + "=" + DBReader.GetValue(1).ToString());
                        System.Console.WriteLine(DBReader.GetName(2).ToString() + "=" + DBReader.GetValue(2).ToString());
                        System.Console.WriteLine(DBReader.GetName(3).ToString() + "=" + DBReader.GetValue(3).ToString());

                        i++;
                }
                DBReader.Close();
                DBConn.Close();
        }
        catch (Exception e)
        {
                System.Console.WriteLine("Err");
        }
}
 
OLEDB SQL2005
public void SQLOleDbConn()
{
        string strConnection = @"Provider=SQLOLEDB;Data Source=机器名\数据库名;Initial Catalog=master;Integrated Security=SSPI;";

        OleDbConnection DBConn;
        OleDbCommand DBCommand;
        OleDbDataReader DBReader;

        try
        {
                DBConn = new OleDbConnection(strConnection);
                DBConn.Open();
                DBCommand = DBConn.CreateCommand();
                DBCommand.CommandText = "select A, B, C, D from TestTable";
                DBReader = DBCommand.ExecuteReader();

                int i = 1;
                while (DBReader.Read())
                {
                        System.Console.WriteLine("=============================================================");
                        System.Console.WriteLine("No" + i);
                        System.Console.WriteLine(DBReader.GetName(0).ToString() + "=" + DBReader.GetValue(0).ToString());
                        System.Console.WriteLine(DBReader.GetName(1).ToString() + "=" + DBReader.GetValue(1).ToString());
                        System.Console.WriteLine(DBReader.GetName(2).ToString() + "=" + DBReader.GetValue(2).ToString());
                        System.Console.WriteLine(DBReader.GetName(3).ToString() + "=" + DBReader.GetValue(3).ToString());

                        i++;
                }
                DBReader.Close();
                DBConn.Close();
        }
        catch (Exception e)
        {
                System.Console.WriteLine("Err");
        }
}
 
SQLClient SQL2005
public void SQLClientConn()
{
        //string strconnection = @"server=机器名\数据库名; database=master;uid=sa;password=123;";
        string strConnection = @"server=localhost\SQLEXPRESS; database=master;uid=sa;password=123;";

        SqlConnection DBConn;
        SqlCommand DBCommand;
        SqlDataReader DBReader;

        try
        {
                DBConn = new SqlConnection(strConnection);
                DBConn.Open();
                DBCommand = DBConn.CreateCommand();
                DBCommand.CommandText = "select A, B, C, D from TestTable";
                DBReader = DBCommand.ExecuteReader();

                int i = 1;
                while (DBReader.Read())
                {
                        System.Console.WriteLine("=============================================================");
                        System.Console.WriteLine("No" + i);
                        System.Console.WriteLine(DBReader.GetName(0).ToString() + "=" + DBReader.GetValue(0).ToString());
                        System.Console.WriteLine(DBReader.GetName(1).ToString() + "=" + DBReader.GetValue(1).ToString());
                        System.Console.WriteLine(DBReader.GetName(2).ToString() + "=" + DBReader.GetValue(2).ToString());
                        System.Console.WriteLine(DBReader.GetName(3).ToString() + "=" + DBReader.GetValue(3).ToString());

                        i++;
                }
                DBReader.Close();
                DBConn.Close();
        }
        catch (Exception e)
        {
                System.Console.WriteLine("Err");
        }
}