骑牛上北京

 

DataSet读取数据

 1 using System.Data;
 2 using System.Data.SqlClient;
 3 
 4 namespace ConsoleApplication3
 5 {
 6     class Program
 7     {
 8         static void Main(string[] args)
 9         {
10             SqlConnection thisConn = new SqlConnection(@"Server=.\Nie;uid=sa;pwd=111;Database=MyNorthwind");
11 
12 
13             SqlDataAdapter thisAdapter = new SqlDataAdapter("select customerId,Address from Customers",
14                                                              thisConn);
15             DataSet thisDataSet = new DataSet();
16             thisAdapter.Fill(thisDataSet, "customers");
17             foreach (DataRow theRow in thisDataSet.Tables["Customers"].Rows)
18             {
19                 Console.WriteLine(theRow["customerId"] + "\t" + theRow["Address"]);
20             }
21             thisConn.Close();
22             Console.Write("Program finished,press any key to Continue.");
23             Console.ReadLine();
24 
25         }
26     }
27 }

 

posted on 2014-03-02 21:54  29882942  阅读(584)  评论(0)    收藏  举报

导航