using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Configuration; namespace SQLQuery { class Program { static void ReadOrderDate(string connectionString) { string queryString = "select DateTime,BuildNum,ComputerID from BasicResults where DateDiff(week,BasicResults.DateTime, GetDate()) < 3"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(String.Format("{0}, {1}, {2}",reader[0], reader[1], reader[2])); } reader.Close(); connection.Close(); } } //Test static void Main(string[] args) { string conStr = ConfigurationManager.AppSettings["connectionString"]; ReadOrderDate(conStr); } } } 参考: http://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldatareader.read(v=VS.80).aspx