using System.Data.SqlClient;namespace TestDB{ class Program { static void Main(string[] args) { string strConn = @" server = (local); integrated security = true; database = Northwind "; string strSQL = "select UnitPrice, UnitsInStock from Products"; SqlConnection cn = new SqlConnection(strConn); SqlDataReader sqlRder = null; try { cn.Open(); SqlCommand cmd = new SqlCommand(strSQL, cn); sqlRder = cmd.ExecuteReader(); //把结果域放到aData数组中 object[] aData = new object[sqlRder.FieldCount]; while (sqlRder.Read()) { //一次读出一行数据,并保存在aData中 sqlRder.GetValues(aData); for (int i = 0; i < aData.Length; ++i) { 逐个读出每列值. System.Console.Write("{0}, ", aData[i].ToString()); } System.Console.WriteLine("\n----------------------------------"); } } catch (System.Exception exp) { System.Console.WriteLine(exp.ToString()); } finally { if (!sqlRder.IsClosed) sqlRder.Close(); cn.Close(); } } }}