private void getData(){#regionSqlConnection 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}
asp.net sqlparameter,dataset合并排序的用法
最新推荐文章于 2012-02-09 13:53:00 发布
本文介绍了一个使用C#和SQL进行数据查询的例子。通过连接数据库并执行SQL查询语句,从两个表中获取学生的报告信息及相关的留言内容,并将这些数据显示在网页上。此外,还实现了根据不同状态显示审核进度的功能。
848

被折叠的 条评论
为什么被折叠?



