读取Sql Server数据库数据
static List<Bumbershoot> GetTalbeFiling() { string server = ConfigurationManager.AppSettings["SqlServer"].ToString(); string database = ConfigurationManager.AppSettings["SqlDatabase"].ToString(); string uid = ConfigurationManager.AppSettings["SqlUserID"].ToString(); string pwd = ConfigurationManager.AppSettings["SqlUserPWD"].ToString();; string connectionString = @"server=" + server + ";database=" + database + ";uid=" + uid + ";pwd=" + pwd; int offday = Convert.ToInt32(ConfigurationManager.AppSettings["offDays"].ToString()); string queryString = "SELECT * FROM [Eform_Data_Output].[dbo].[TB_Non_Bumbershoot_EV] a left join [Eform_Data_Output].[dbo].[TB_NotesName] b"; queryString += " on a.EVRequestor=b.Owner where Cast(a.gtCompleteDate as date)>=Cast(dateadd(day,-"+offday+",getdate())as date)"; queryString += " and Cast(a.gtCompleteDate as date)<Cast(getdate() as date) and a.gtWFStatus='Approved'"; List<Bumbershoot> oList = new List<Bumbershoot>(); using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); command.CommandTimeout = 0; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { //业务操作 } reader.Close(); connection.Close(); } return oList; }
posted on 2019-04-17 13:44 赢在当下_Victor 阅读(676) 评论(0) 编辑 收藏 举报