日期:2014-05-17 浏览次数:20429 次
DataTable dt = new DataTable(); dt.Columns.Add("收缩压上", typeof(int)); dt.Columns.Add("舒张压下", typeof(int)); dt.Columns.Add("血糖餐前", typeof(int)); dt.Columns.Add("血糖餐后", typeof(int)); dt.Columns.Add("体温", typeof(float)); dt.Columns.Add("心率", typeof(int)); dt.Columns.Add("时间", typeof(string)); OleDbData md = new OleDbData(); md.ExecuteReader("select * from Test"); //请改成自己的sql语句 DataRow dr = null; while (md.Reader.Read()) { if (md.Reader["typename"].ToString() == "收缩压上") { dr = dt.NewRow(); dt.Rows.Add(dr); } dr[md.Reader["typename"].ToString()] = md.Reader["collectdata"]; if (md.Reader["typename"].ToString() == "心率") dr["时间"] = ((DateTime)md.Reader["collecttime"]).ToString("HH时mm分"); } md.Close(); GridView1.DataSource = dt; GridView1.DataBind();
------解决方案--------------------
地址贴错了,运行结果如下:
------解决方案--------------------
dt换成你从数据库中查询出来的数据。
static void Main(string[] args) { DataTable dt = new DataTable(); dt.Columns.Add("collectdata"); dt.Columns.Add("typename"); dt.Columns.Add("collecttime"); dt.Rows.Add(new object[] { "120.00", "收缩压上", "2012/5/11 13:19:45" }); dt.Rows.Add(new object[] { "90.00", "舒张压下", "2012/5/11 13:19:46" }); dt.Rows.Add(new object[] { "34.00", "血糖餐前", "2012/5/11 13:19:47" }); dt.Rows.Add(new object[] { "36.00", "血糖餐后", "2012/5/11 13:19:48" }); dt.Rows.Add(new object[] { "37.50", "体温", "2012/5/11 13:19:49" }); dt.Rows.Add(new object[] { "180.00", "收缩压上", "2012/5/11 16:30:31" }); dt.Rows.Add(new object[] { "110.00", "舒张压下", "2012/5/11 16:30:31" }); dt.Rows.Add(new object[] { "33.00", "血糖餐前", "2012/5/11 16:30:33" }); dt.Rows.Add(new object[] { "38.00", "血糖餐后", "2012/5/11 16:30:34" }); dt.Rows.Add(new object[] { "39.00", "体温", "2012/5/11 16:30:35" }); dt.Rows.Add(new object[] { "190.00", "心率", "2012/5/11 16:30:36" }); dt.Rows.Add