update event handler doesn't recognize the updated values

R

Rushmi

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;
}

}


}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top