update event handler doesn't recognize the updated values

Discussion in 'ASP .Net Web Controls' started by Rushmi, Jul 17, 2003.

  1. Rushmi

    Rushmi Guest

    The below page is a work in progress .Upon update, I've
    been able to successfully update the DB but the new values
    are not recognized. (Print statements reveal that the
    below statement is returning stale values)
    String priority = ((System.Web.UI.WebControls.TextBox)
    e.Item.Cells[1].Controls[0]).Text;
    Has anyone had similar issues?
    Thx
    --------------------------------------------------


    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using forecast.db;
    using System.Data.OracleClient;

    //using System.Data.OleDb;

    namespace forecast
    {
    /// <summary>
    /// Summary description for WebForm1.
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Label
    lbProjects;
    protected
    System.Web.UI.WebControls.DataGrid DGProjects;
    protected System.Web.UI.WebControls.Panel
    p;
    protected System.Web.UI.WebControls.Panel
    Panel1;

    private void Page_Load(object sender,
    System.EventArgs e)
    {
    // Put user code to initialize the
    page here
    BindGrid();
    }

    private void BindGrid()
    {
    DBAccess db = new DBAccess();
    OracleConnection myConnection =
    db.GetDBConnection();
    OracleDataAdapter myAdopter = new
    OracleDataAdapter("select * from project", myConnection);

    DataSet ds = new DataSet();
    myAdopter.Fill(ds, "project");

    DGProjects.DataSource=ds.Tables
    ["project"].DefaultView;
    DGProjects.DataBind();
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: This call is required
    by the ASP.NET Web Form Designer.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support -
    do not modify
    /// the contents of this method with the
    code editor.
    /// </summary>
    private void InitializeComponent()
    {

    this.DGProjects.SelectedIndexChanged += new
    System.EventHandler(this.DGProjects_SelectedIndexChanged);
    this.Load += new
    System.EventHandler(this.Page_Load);

    }
    #endregion
    /*
    private void DataList1_SelectedIndexChanged
    (object sender, System.EventArgs e)
    {

    }
    */
    private void
    DGProjects_SelectedIndexChanged(object sender,
    System.EventArgs e)
    {

    }

    protected void DGProjects_Cancel(object
    sender, DataGridCommandEventArgs e)
    {
    DGProjects.EditItemIndex = -1;
    BindGrid();
    }
    protected void DGProjects_Edit(object
    sender, DataGridCommandEventArgs e)
    {
    DGProjects.EditItemIndex = (int)
    e.Item.ItemIndex;
    BindGrid();
    }
    protected void DGProjects_Update(object
    sender, DataGridCommandEventArgs e)
    {
    System.Web.UI.WebControls.TextBox
    t = (System.Web.UI.WebControls.TextBox)e.Item.Cells
    [1].Controls[0];
    // Response.Write("cell 0 , value
    is=" + t.Text );

    String priority =
    ((System.Web.UI.WebControls.TextBox)e.Item.Cells
    [1].Controls[0]).Text;
    String projectName =
    ((System.Web.UI.WebControls.TextBox)e.Item.Cells
    [2].Controls[0]).Text;
    String projectStDt =
    ((System.Web.UI.WebControls.TextBox)e.Item.Cells
    [3].Controls[0]).Text;
    String projectEndDt =
    ((System.Web.UI.WebControls.TextBox)e.Item.Cells
    [4].Controls[0]).Text;
    String projectDesc =
    ((System.Web.UI.LiteralControl)e.Item.Cells[5].Controls
    [0]).Text;

    // Gets the value of the key field
    of the row being updated
    String key = DGProjects.DataKeys
    [(int)e.Item.ItemIndex].ToString();

    string updateCmd = "UPDATE project
    SET " +
    "PRIORITY = " + priority
    + " ," +
    "PROJECT_NAME = '" +
    projectName + "' ," +
    "APPROX_PROJECT_BEGIN_DATE
    = to_date('" + projectStDt + "','mm/dd/yyyy') ,"
    +
    "APPROX_PROJECT_END_DATE =
    to_date('" + projectEndDt + "','mm/dd/yyyy') ,"
    +
    //"DEPT_ID = '" +
    e.Item.Cells[2].Controls[0] + "' ," +
    "PROJECT_DESC= '" + projectDesc + "' " +
    "WHERE project_id = " +
    key ;

    Response.Write("the command is = "
    + updateCmd + "/n" );
    Response.Write("-------------------------------------------
    ---------------");

    try {
    DBAccess db = new DBAccess();
    OracleConnection myConnection =
    db.GetDBConnection();
    myConnection.Open();
    OracleTransaction myTrans =
    myConnection.BeginTransaction
    (IsolationLevel.ReadCommitted);

    OracleCommand myCommand = new
    OracleCommand(updateCmd, myConnection);
    myCommand.Transaction = myTrans;
    myCommand.CommandType =
    CommandType.Text;

    myCommand.ExecuteNonQuery();
    myTrans.Commit();

    myCommand.Connection.Close();

    DGProjects.EditItemIndex = -1; //
    leave user in edit mode on exception
    }
    catch (Exception exc)
    {
    Response.Write(exc);

    DGProjects.EditItemIndex
    = -1;
    }

    }


    }
    }
     
    Rushmi, Jul 17, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dennis M
    Replies:
    2
    Views:
    459
    Dennis M
    Feb 11, 2006
  2. =?Utf-8?B?S2V2aW4=?=
    Replies:
    3
    Views:
    11,436
    Walter Wang [MSFT]
    Jun 17, 2006
  3. Replies:
    1
    Views:
    711
    Damien
    Feb 22, 2007
  4. Steve Kershaw
    Replies:
    1
    Views:
    2,316
    David R. Longnecker
    Sep 21, 2007
  5. Dmitry Korolyov

    Datagrid not updated during delete, but updated during insert and update

    Dmitry Korolyov, Sep 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    418
    Dmitry Korolyov
    Sep 22, 2003
Loading...

Share This Page