asp.net sqlparameter,dataset合并排序的用法

 private void getData()
        {
            #region
            SqlConnection sqlconn= new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
            SqlCommand cmd = new SqlCommand("select * from open_report, student_login where open_report.studentNum "
+"= student_login.studentNum and open_report.Id = @openID",sqlconn);
            SqlParameter openID = new SqlParameter("@openID", Request.QueryString["openID"].ToString());
            cmd.Parameters.Add(openID);
            SqlDataAdapter sqlAdp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sqlAdp.Fill(ds);
            LabStuID.Text=ds.Tables[0].Rows[0]["studentNum"].ToString();
            labName.Text = ds.Tables[0].Rows[0]["studentName"].ToString();
            labTitle.Text=ds.Tables[0].Rows[0]["reportTitle"].ToString();
            linkDownload.NavigateUrl=ds.Tables[0].Rows[0]["attachFilePath"].ToString();
            labTime.Text = ds.Tables[0].Rows[0]["uploadTime"].ToString();
            switch(ds.Tables[0].Rows[0]["passState"].ToString().Trim())
            {
                case "0":
                    labState.Text = "审核中";
                    break;
                case "1":
                    labState.Text = "审核未通过";
                    break;
                case "2":
                    labState.Text = "审核通过";
                    break;
            }
            #endregion
            #region 获得留言内容
            cmd.CommandText = "select studentName as StudentName,replyTime as LeaveMessageTime,replyContent"+
" as Content from open_reply,student_login where senderNum=studentNum and open_id = @openID";
            SqlDataAdapter sqlAdp1 = new SqlDataAdapter(cmd);
            DataSet ds1 = new DataSet();
            sqlAdp1.Fill(ds1);
            cmd.CommandText = "select teacher_Name as TeacherName,replyTime as LeaveMessageTime, "+
"replyContent as Content from open_reply,teacher_detail where senderNum=teacher_Id and open_id = @openID";
            SqlDataAdapter sqlAdp2 = new SqlDataAdapter(cmd);
            DataSet ds2 = new DataSet();
            sqlAdp2.Fill(ds2);
            ds1.Merge(ds2);
            DataView dv = new DataView();
            dv.Table = ds1.Tables[0];
            dv.Sort = "LeaveMessageTime desc";
            GridView1.DataSource = dv;
            GridView1.DataBind();
            #endregion
        }

你可能感兴趣的:(cmd,report,asp.net,login,dataset)