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); } } }}
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18