日期:2014-05-18  浏览次数:20600 次

结果怎么这样啊,该如何改?
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"