首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

结果如何这样啊该怎么改

2012-04-03 
结果怎么这样啊,该如何改?C# codeSqlConnection con dataOperate.createCon()con.Open()DataSet dssq

结果怎么这样啊,该如何改?

C# code
  SqlConnection con = dataOperate.createCon();            con.Open();            DataSet ds;            sql1 = "select userid,moterid,startdate,startengy from UserDayEngy where userid='"+ strUser +"' and moterid='" + strMoter + "'and datetime='"+startDate+"'";            SqlDataAdapter sda = new SqlDataAdapter(sql1, con);            ds = new DataSet();            sda.Fill(ds, "singlemoter");            sql2 = "select enddate,endengy from UserDayEngy where userid='" + strUser + "' and moterid='" + strMoter + "'and datetime='" + endDate + "'";            SqlDataAdapter sda1 = new SqlDataAdapter(sql2, con);            sda1.Fill(ds, "Singlemoter");            MonthsElectricityNumber.DataSource = ds;            BoundField field;            field = new BoundField();            field.DataField="userid";            field.HeaderText = "用户编号";            MonthsElectricityNumber.Columns.Add(field);            field = new BoundField();            field.DataField = "moterid";            field.HeaderText = "电表编号";            MonthsElectricityNumber.Columns.Add(field);            field = new BoundField();            field.DataField = "startdate";            field.HeaderText = "起始日期";            MonthsElectricityNumber.Columns.Add(field);            field = new BoundField();            field.DataField = "startengy";            field.HeaderText = "起始电量";            MonthsElectricityNumber.Columns.Add(field);            field = new BoundField();            field.DataField = "enddate";            field.HeaderText = "终止日期";            MonthsElectricityNumber.Columns.Add(field);            field = new BoundField();            field.DataField = "endengy";            field.HeaderText = "终止电量";            MonthsElectricityNumber.Columns.Add(field);            MonthsElectricityNumber.DataBind();            

结果运行:

我想要的结果应该在同一行中,怎么跑到不同行中了?
 

[解决办法]
可以
sql = "select t1.*, t2.enddate, t2.endengy from (select userid,moterid,startdate,startengy from UserDayEngy where userid='"+ strUser +"' and moterid='" + strMoter + "'and datetime='"+startDate+"') t1 left join (select userid, enddate,endengy from UserDayEngy where userid='" + strUser + "' and moterid='" + strMoter + "'and datetime='" + endDate + "') t2 on t1.userid=t2.userid"

热点排行