主表保存:
 public void Button1_OnClick(object sender, EventArgs e)
    {
        pd = GetCount();
        if (pd)
        {ref_ID=Convert.ToInt32(Session["id"]);
            Str_insert = @"insert into 申报_GHTJSBB (Z_id,申报人姓名,申报业务,申报日期) values(Z_id.NEXTVAL,'"  + 申报人姓名.Text + "','意见书申报','"            + 申报日期.Text + "')";            DbHelperOra.Query(Str_insert);
            
        }
       
-----------子表保存代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
      
       
        
        string _insert4 = @"insert into XZYJS_NJXM(id,拟定项目,备注,REF_申报_ID) values(id.NEXTVAL, '" 
            + (this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0] as TextBox).Text + "','" 
            + (this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0] as TextBox).Text + "','"+Z_id+"')";
        DbHelperOra.Query(_insert4);
        }我想在子表保存时,把主表的Z_id做为子表的REF_申报_ID值插入.
我写了'"+Z_id+"'可是在跟踪时显示为0,并不是主表的Z_id值.
请问高手这块该怎么写呢?如何才能得到主表的Z_id值.
非常感谢~!在线请教!~!

解决方案 »

  1.   

    你的Z_id从哪儿获得的值?为什么不用存储过程?
      

  2.   

    1.static 
    2.隐藏栏位
    3.视图状态这三种方法都可以,自己选择吧。
      

  3.   

    这两个事件 第一个发生了 第二个不一定发生时吗? Z_id从哪里来的  在获得一遍Z_id值不可以吗?  你这种设计很奇怪?好像没有意义! 在事件外设置一个Z_id属性吧 每次改变后在class中哪里都能用
      

  4.   

    是WebForm吧,Asp.net不保存状态的,用ViewState来保存。