C# ado.net oledb方式连接(三)

oledb 方式连接

 1   class Program
 2     {
 3         private static string constr = "server=.;database=northwnd;integrated security=sspi";
 4         static void Main(string[] args)
 5         {
 6             string source = "provider=sqloledb;" + constr;
 7             string select = "select contactname,companyname from customers";
 8             OleDbConnection con = new OleDbConnection(source);
 9             con.Open();
10             OleDbCommand cmd = new OleDbCommand(select, con);
11             OleDbDataReader reader = cmd.ExecuteReader();
12             while (reader.Read())
13                 Console.WriteLine("{0} from {1}", reader.GetString(0), reader.GetString(1));
14             reader.Close();
15             con.Close();
16         }
17 
18     }

 

posted @ 2017-01-05 17:20  指间的徘徊  阅读(1458)  评论(0编辑  收藏  举报