我写留言板写了一半,无须注册的那种。
有2个表,一个表放留言记录,一个表放回复记录。
在回复页面我需要首先显示一条留言(通过点上一页的连接进入),下面跟着这条留言的回复。代码如何写呀,我写的是用2个conn对象和dataset绑定数据显示。能不能共享一个connection对象,给我一个大概的结构好吗?

解决方案 »

  1.   

    OleDbDataAdapter da = new OleDbDataAdapter(sqlReply,conn);
    DataSet ds = new DataSet();
    da.Fill(ds,"reply");
    中的 "reply" 是什么东西,自己定义的吗?还是表名?
      

  2.   

    就是在一个页面使用2个或以上的数据绑定
    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!Page.IsPostBack)
    {
    DataLoad();
    ReplyData();
    }
    }public void DataLoad()
    {
    string replyID = Request.Params["replyID"];
    string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(".") + "\\database\\data.mdb";
    string sqlStr = "SELECT * FROM gbook where id=" + replyID;
    conn = new OleDbConnection(conStr);conn.Open();
    OleDbDataAdapter da = new OleDbDataAdapter(sqlStr,conn);

    //填充数据集
    DataSet ds = new DataSet();
    da.Fill(ds,"Message");
    message.DataSource = ds;
    message.DataMember = "Message";
    message.DataBind();
    conn.Close();
    }public void ReplyData()
    {
    string replyID = Request.Params["replyID"];
    string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(".") + "\\database\\data.mdb";
    string sqlReply = "SELECT * FROM reply WHERE replyID=" + replyID;
    conn = new OleDbConnection(conStr);
    conn.Open();
    b_memo.Text = "bbb";
    OleDbDataAdapter dar = new OleDbDataAdapter(sqlReply,conn);

    //填充数据集
    DataSet dsr = new DataSet();
    dar.Fill(dsr,"message1");
    replyMessage.DataSource = dsr;
    replyMessage.DataMember = "replyMessage";
    replyMessage.DataBind();
    }老是出错