新闻添加页:add.aspx.cs    protected void btnADD_Click(object sender, EventArgs e)
    {
        type t = new type();
        t.newsTitle = this.txtnewsTitle.Text;
        t.newsText = this.txtnewsText.Text;
        if (master.insertOperate(t))
        {
            txtnewsTitle.Text = "";
            txtnewsText.Text = "";
            Response.Redirect("add-up.aspx");
        }
        else
        {
            Response.Write("添加失败!");
        }
接收页:add-up.aspx.cs    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = DB.createCon();
        con.Open();
        string strID = Request.Form.Get("newsID").ToString();
        SqlCommand cmd = new SqlCommand("select * from newsMaster where newsID='" + strID + "'", con);
        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();
        this.Label1.Text = dr["newsTitle"].ToString();
        this.Label2.Text = dr["newsText"].ToString();
        dr.Close();
    }新闻主键:newsID
新闻标题:newsTitle
新闻内容:newsText要实现,在add.aspx添加成功后,跳转到add-up.aspx后,add-up.aspx要能接受到刚才添加成功的那一列的内容.(注:不是用session保存,因为要获得刚才添加成功后的那一列的主键.)
上面我写的add-up.aspx.cs的代码是不对的,哪位能帮我写个正确的,必当感激不尽.

解决方案 »

  1.   

    add.aspx.cs
    Response.Redirect("add-up.aspx?newsID=1&newsTitle=2&newsText=3");add-up.aspx.csstring newsID = Request.Params["newsID"];
    string newsTitle= Request.Params["newsTitle"];
    string newsText= Request.Params["newsText"];
      

  2.   

    add.aspx.cs
    Response.Redirect("add-up.aspx?newsID=1&newsTitle=2&newsText=3");add-up.aspx.csstring newsID = Request.Params["newsID"];
    string newsTitle= Request.Params["newsTitle"];
    string newsText= Request.Params["newsText"];我要的好象不是这样的意思,因为newsID为主键是自动增长的,添加的时候不知道newsID为几,但要让接受页知道刚才添加成功的那个主键是多少.
      

  3.   

    用传参 然后用me.request.query("查询条件的主键")取得主键  然后通过SQL语句就可以查到所有的值了!!
      

  4.   

    用传参 然后用me.request.query("查询条件的主键")取得主键  然后通过SQL语句就可以查到所有的值了!!可以写个例子吗?小弟菜鸟一只啊.
    意思就是让一个接收页能知道刚才添加成功的那一列的主键.
      

  5.   

    Response.Redirect("add-up.aspx?newsID=1"+t.newsID)up:
    type t = (type)Manager.....GetObject(typeof(type), Request.Params["newsID"]);
    (是用的ORM吗?)
     t.newsTitle ;
     t.newsText ;
      

  6.   

    但我有一点不明白
     protected void btnADD_Click(object sender, EventArgs e)
    你插入的的INSERT语句应该写在这按钮下的 所以当你点这按钮时候这数据就存到数据库中了
    所以下个页面就从数据库中取啊!
      

  7.   

    假如你插入语句插入的主键是USID的话 
    那么紧接着你再写个select语句 select USID(主键) from 表 
    然后转页面时候传参
    Response.Redirect("add-up.aspx?USID=选出的主键)
    在下个页面用request接受
      

  8.   

    插入语句里返回自增的id就可以了
    string sql = "insert into testtable values('aaa');select @@identity as newid";
    SqlCommand cmd = new SqlCommand(sql,con);
    int newid = (int)cmd.ExecuteScalar();
    这样就可以取到这个新增的id,然后传到下个页面