论坛,显示回复留言中的左边,显示回复人的个人资料之判断条件
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace 仿大家网论坛
{
public partial class xxnr : System.Web.UI.Page
{
//string id = System Request.QueryString["id"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
int id = Convert.ToInt32(Request.QueryString["id"]);
//string classa = Request.QueryString["class"].ToString();
SqlConnection sqlCon = new SqlConnection();
sqlCon.ConnectionString = "server=.;uid=sa;pwd=sa;database=topsagecom";
//string SqlStr = "select * from niankaoyan where id=" + id;
// string SqlStr = "select * from table1";
//string SqlStr = "select u.id,u.username,u.touxiang,t.id,t.title,t.time,t.content,t.class from usermessage u left join table1 t on u.username=t.username";
string SqlStr = "select id,username,time,content from huifubiao where huifuid="+id; //查询回复留言信息
//SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon);
//DataSet ds = new DataSet();
// da.Fill(ds, "table1");
SqlDataAdapter da2 = new SqlDataAdapter(SqlStr, sqlCon);
DataSet ds2 = new DataSet();
//this.DataList3.ItemDataBound += new DataListItemEventHandler(DataList3_ItemDataBound);
da2.Fill(ds2, "table1");
//this.DataList3.ItemDataBound += new DataListItemEventHandler(DataList3_ItemDataBound);
//this.DataList3.DataSource = ds2.Tables["table1"].DefaultView;
this.DataList3.DataSource = ds2.Tables["table1"];
//this.DataList3.DataKeyField = "id";
this.DataList3.DataBind(); //帖子回复显示代码
//string SqlStr4="select b.username,a.touxiang,b.title,b.time,b.content from usermessage a full join table1 b on a.username=b.username where b.id='1'";
//string SqlStr4 = "select top 1 * from table1 where id='1'"; //发帖标题、时间、内容
string SqlStr4 = "select title,username,time,content from messagelist where id="+id;
SqlDataAdapter da4 = new SqlDataAdapter(SqlStr4, sqlCon);
DataSet ds4 = new DataSet();
this.DataList4.ItemDataBound += new DataListItemEventHandler(DataList4_ItemDataBound);
da4.Fill(ds4, "table1");
this.DataList4.DataSource = ds4.Tables["table1"];
this.DataList4.DataBind(); //楼主的标题、内容...
}
protected void DataList4_ItemDataBound(object sender, DataListItemEventArgs e) //发帖人个人信息
{
// string id2 = Request.QueryString["id"].ToString();
//string classa2 = Request.QueryString["class"].ToString();
int id = Convert.ToInt32(Request.QueryString["id"]);
SqlConnection sqlCon2 = new SqlConnection();
sqlCon2.ConnectionString = "server=.;uid=sa;pwd=sa;database=topsagecom";
//string SqlStr2 = "select username,id from [" + classa2 + "] where id=" + id2; // select username,id from user where username=(select username from [" + classa2 + "] where id=" + id2)
//string SqlStr2 = "select top 1 username,touxiang from usermessage where username=(select username from table1 where id=+'1'+)";
//string SqlStr2 = "SELECT TOP (1) PERCENT dbo.usermessage.username, dbo.table1.title, dbo.table1.time, dbo.table1.[content], dbo.usermessage.touxiang FROM dbo.table1 INNER JOIN dbo.usermessage ON dbo.table1.username = dbo.usermessage.username ORDER BY dbo.table1.time";
string SqlStr2 = "select username,touxiang from usermessage where username=(select username from messagelist where id="+id+")";
SqlDataAdapter da2 = new SqlDataAdapter(SqlStr2, sqlCon2);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "abc");
DataList dl = (DataList)e.Item.FindControl("DataList5");
dl.DataSource = ds2.Tables["abc"];
dl.DataBind();
}
protected void DataList3_ItemDataBound(object sender, DataListItemEventArgs e) //回帖人个人信息
{
// string id2 = Request.QueryString["id"].ToString();
//string classa2 = Request.QueryString["class"].ToString();
int id = Convert.ToInt32(Request.QueryString["id"]);
SqlConnection sqlCon2 = new SqlConnection();
sqlCon2.ConnectionString = "server=.;uid=sa;pwd=sa;database=topsagecom";
//string SqlStr2 = "select username,id from [" + classa2 + "] where id=" + id2; // select username,id from user where username=(select username from [" + classa2 + "] where id=" + id2)
//string SqlStr2 = "select top 1 username,touxiang from usermessage where username=(select username from table1 where id=+'1'+)";
//string SqlStr2 = "SELECT TOP (1) PERCENT dbo.usermessage.username, dbo.table1.title, dbo.table1.time, dbo.table1.[content], dbo.usermessage.touxiang FROM dbo.table1 INNER JOIN dbo.usermessage ON dbo.table1.username = dbo.usermessage.username ORDER BY dbo.table1.time";
string SqlStr2 = "select username,touxiang from usermessage where username=(select username from huifubiao where huifuid=" + id + ")";
SqlDataAdapter da2 = new SqlDataAdapter(SqlStr2, sqlCon2);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "abc");
DataList dl = (DataList)e.Item.FindControl("DataList6");
dl.DataSource = ds2.Tables["abc"];
dl.DataBind();
}
public int sqlEx(string sqlstr) //执行sql语句
{
int res;
string con = "server=.;uid=sa;pwd=sa;database=topsagecom";
SqlConnection conn = new SqlConnection(con);
conn.Open();
SqlCommand cmd = new SqlCommand(sqlstr, conn);
res = cmd.ExecuteNonQuery(); //返回受影响的行数
conn.Close();
return res;
}
protected void Button3_Click(object sender, EventArgs e) //发表回复事件
{
int id = Convert.ToInt32(Request.QueryString["id"]);
string sqlstr = "insert into huifubiao (username,time,content,huifuid) values('" + 1 + "','" + DateTime.Now + "','" + TextBox1.Text.ToString() + "',"+id+")";
sqlEx(sqlstr);
}
}
} --------------------编程问答-------------------- 我把发表留言和回复留言分别建一个表,发表留言messagelist,回复留言huifubiao
现在就查根据传递什么值进去,去查找出回帖的人的个人资料呢?
上面那句红色的就是:
string SqlStr2 = "select username,touxiang from usermessage where username=(select username from huifubiao where huifuid=" + id + ")";
--------------------编程问答-------------------- 回复表就这几个字段:
[id]
,[username]
,[time]
,[content]
,[huifuid]
补充:.NET技术 , ASP.NET