473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

updating a DataGrid

Hi, I am trying to use a data grid in a web application in which I have
three tiers. The DataGrid is not set up to a data source, or a data adapter,
so everytime I make a change I send the cell information to another object
which forms an SQL query and makes the query to the DB (actually to a
DBFacade object). In any case, please see the code I have listed below for
my update DataGrid event. With this code, the DB is updated using the old
data in the datagrid prior to the users changes, why is this and how can I
take the new data out of the grid after the user makes changes? Thanks very
much!

private void coursesDataGrid_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// get primary key courseID
TableCell courseIDCell = e.Item.Cells[1];
string courseID = ((TextBox)courseIDCell.Controls[0]).Text;

// get section
TableCell sectionCell = e.Item.Cells[2];
string section = ((TextBox)sectionCell.Controls[0]).Text;

// get semester
TableCell semesterCell = e.Item.Cells[3];
string semester = ((TextBox)semesterCell.Controls[0]).Text;

// get title
TableCell titleCell = e.Item.Cells[4];
string title = ((TextBox)titleCell.Controls[0]).Text;

// get school name
TableCell schoolNameCell = e.Item.Cells[5];
string schoolName = ((TextBox)schoolNameCell.Controls[0]).Text;

// update database here
coursesDataGrid.DataSource = courseManager.UpdateCourse(user, schoolName,
semester, courseID, title, section);

coursesDataGrid.EditItemIndex = -1;
coursesDataGrid.DataBind();
}

Jon Agiato
Nov 18 '05 #1
3 1775
Jon,

Without seeing how UpdateCourse works, it is difficult to tell. Is that
data that you are passing into the function being stored in a datatable or is
it directly updating your database layer? If that is within a datatable, be
sure that you are accepting changes before going forward to your data layer.

If this isn't your solution, please post the code to the UpdateCourse
function.

Thanks,
Ian Suttle
http://www.IanSuttle.com

"Jon Agiato" wrote:
Hi, I am trying to use a data grid in a web application in which I have
three tiers. The DataGrid is not set up to a data source, or a data adapter,
so everytime I make a change I send the cell information to another object
which forms an SQL query and makes the query to the DB (actually to a
DBFacade object). In any case, please see the code I have listed below for
my update DataGrid event. With this code, the DB is updated using the old
data in the datagrid prior to the users changes, why is this and how can I
take the new data out of the grid after the user makes changes? Thanks very
much!

private void coursesDataGrid_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// get primary key courseID
TableCell courseIDCell = e.Item.Cells[1];
string courseID = ((TextBox)courseIDCell.Controls[0]).Text;

// get section
TableCell sectionCell = e.Item.Cells[2];
string section = ((TextBox)sectionCell.Controls[0]).Text;

// get semester
TableCell semesterCell = e.Item.Cells[3];
string semester = ((TextBox)semesterCell.Controls[0]).Text;

// get title
TableCell titleCell = e.Item.Cells[4];
string title = ((TextBox)titleCell.Controls[0]).Text;

// get school name
TableCell schoolNameCell = e.Item.Cells[5];
string schoolName = ((TextBox)schoolNameCell.Controls[0]).Text;

// update database here
coursesDataGrid.DataSource = courseManager.UpdateCourse(user, schoolName,
semester, courseID, title, section);

coursesDataGrid.EditItemIndex = -1;
coursesDataGrid.DataBind();
}

Jon Agiato

Nov 18 '05 #2
Hi Ian, and thanks for the reply.

The application is set up using the layers pattern. The UI layer which is
the code you see here takes the values from the controls, and passes it back
to a controller object, which is shown here as courseManager. The
controller object takes the data, formulates the appropriate SQL query, and
passes it back to a database facade object, whch then performs the action
query to update the row with the primary key passed with the new
information. The method called here on courseManager also makes a call to
the db facade object to retrieve a new copy of the table after the
operations are completed and returns a data table, which the UI layer then
assigns to the grid and rebinds so that the new grid is shown with the
updates. Viewstate is disabled for the grid.

Here's the code for the UpdateCourse method on courseManager:

public DataTable UpdateCourse(string username, string schoolName, string
semester, string courseID, string title, string section)
{
string queryString = "Update CTCourses Set CourseID = '" + courseID + "',
Section = '" + section + "', Semester = '" + semester + "', Title = '" +
title + "', SchoolName = '" + schoolName + "' Where Username = '" +
username + "' AND CourseID = '" + courseID + "';";
dbFacade.ActionQuery(queryString);

return this.RetrieveCourses(username);
}

The call to this.RetrieveCourses returns a new copy of the table as a
DataTable.

Thanks to Ian, and any who can help.

Best wishes,

Jon Agiato
"Ian Suttle" <Ia*******@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
Jon,

Without seeing how UpdateCourse works, it is difficult to tell. Is that
data that you are passing into the function being stored in a datatable or
is
it directly updating your database layer? If that is within a datatable,
be
sure that you are accepting changes before going forward to your data
layer.

If this isn't your solution, please post the code to the UpdateCourse
function.

Thanks,
Ian Suttle
http://www.IanSuttle.com

"Jon Agiato" wrote:
Hi, I am trying to use a data grid in a web application in which I have
three tiers. The DataGrid is not set up to a data source, or a data
adapter,
so everytime I make a change I send the cell information to another
object
which forms an SQL query and makes the query to the DB (actually to a
DBFacade object). In any case, please see the code I have listed below
for
my update DataGrid event. With this code, the DB is updated using the old
data in the datagrid prior to the users changes, why is this and how can
I
take the new data out of the grid after the user makes changes? Thanks
very
much!

private void coursesDataGrid_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// get primary key courseID
TableCell courseIDCell = e.Item.Cells[1];
string courseID = ((TextBox)courseIDCell.Controls[0]).Text;

// get section
TableCell sectionCell = e.Item.Cells[2];
string section = ((TextBox)sectionCell.Controls[0]).Text;

// get semester
TableCell semesterCell = e.Item.Cells[3];
string semester = ((TextBox)semesterCell.Controls[0]).Text;

// get title
TableCell titleCell = e.Item.Cells[4];
string title = ((TextBox)titleCell.Controls[0]).Text;

// get school name
TableCell schoolNameCell = e.Item.Cells[5];
string schoolName = ((TextBox)schoolNameCell.Controls[0]).Text;

// update database here
coursesDataGrid.DataSource = courseManager.UpdateCourse(user, schoolName,
semester, courseID, title, section);

coursesDataGrid.EditItemIndex = -1;
coursesDataGrid.DataBind();
}

Jon Agiato

Nov 18 '05 #3
From what you have posted, it looks good. Can you post the ActionQuery and
RetrieveCourses functions? We'll get down to the bottom of it somewhere in
here. Also, try putting debug info throughout and see where the
miscommunication is occurring.

Thanks,
Ian Suttle
http://www.IanSuttle.com

"Jon Agiato" wrote:
Hi Ian, and thanks for the reply.

The application is set up using the layers pattern. The UI layer which is
the code you see here takes the values from the controls, and passes it back
to a controller object, which is shown here as courseManager. The
controller object takes the data, formulates the appropriate SQL query, and
passes it back to a database facade object, whch then performs the action
query to update the row with the primary key passed with the new
information. The method called here on courseManager also makes a call to
the db facade object to retrieve a new copy of the table after the
operations are completed and returns a data table, which the UI layer then
assigns to the grid and rebinds so that the new grid is shown with the
updates. Viewstate is disabled for the grid.

Here's the code for the UpdateCourse method on courseManager:

public DataTable UpdateCourse(string username, string schoolName, string
semester, string courseID, string title, string section)
{
string queryString = "Update CTCourses Set CourseID = '" + courseID + "',
Section = '" + section + "', Semester = '" + semester + "', Title = '" +
title + "', SchoolName = '" + schoolName + "' Where Username = '" +
username + "' AND CourseID = '" + courseID + "';";
dbFacade.ActionQuery(queryString);

return this.RetrieveCourses(username);
}

The call to this.RetrieveCourses returns a new copy of the table as a
DataTable.

Thanks to Ian, and any who can help.

Best wishes,

Jon Agiato
"Ian Suttle" <Ia*******@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
Jon,

Without seeing how UpdateCourse works, it is difficult to tell. Is that
data that you are passing into the function being stored in a datatable or
is
it directly updating your database layer? If that is within a datatable,
be
sure that you are accepting changes before going forward to your data
layer.

If this isn't your solution, please post the code to the UpdateCourse
function.

Thanks,
Ian Suttle
http://www.IanSuttle.com

"Jon Agiato" wrote:
Hi, I am trying to use a data grid in a web application in which I have
three tiers. The DataGrid is not set up to a data source, or a data
adapter,
so everytime I make a change I send the cell information to another
object
which forms an SQL query and makes the query to the DB (actually to a
DBFacade object). In any case, please see the code I have listed below
for
my update DataGrid event. With this code, the DB is updated using the old
data in the datagrid prior to the users changes, why is this and how can
I
take the new data out of the grid after the user makes changes? Thanks
very
much!

private void coursesDataGrid_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// get primary key courseID
TableCell courseIDCell = e.Item.Cells[1];
string courseID = ((TextBox)courseIDCell.Controls[0]).Text;

// get section
TableCell sectionCell = e.Item.Cells[2];
string section = ((TextBox)sectionCell.Controls[0]).Text;

// get semester
TableCell semesterCell = e.Item.Cells[3];
string semester = ((TextBox)semesterCell.Controls[0]).Text;

// get title
TableCell titleCell = e.Item.Cells[4];
string title = ((TextBox)titleCell.Controls[0]).Text;

// get school name
TableCell schoolNameCell = e.Item.Cells[5];
string schoolName = ((TextBox)schoolNameCell.Controls[0]).Text;

// update database here
coursesDataGrid.DataSource = courseManager.UpdateCourse(user, schoolName,
semester, courseID, title, section);

coursesDataGrid.EditItemIndex = -1;
coursesDataGrid.DataBind();
}

Jon Agiato


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: cwbp17 | last post by:
Have two tables that have a FK relationship on ID column. Have one datagrid that displays all of the columns of both tables. What's the best approach on updating a row from the datagrid back to...
1
by: Patrick Delifer | last post by:
HI, I am trying to update a DataGrid where I want to rebind just the row that was updated. Here's the situation: 1) Updating is not a problem, it works fine. 2) I am not using ItemCommand (edit,...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
0
by: cwbp17 | last post by:
I'm having trouble updating individual datagrid cells. Have two tables car_master (columns include Car_ID, YEAR,VEHICLE) and car_detail (columns include Car_ID,PRICE,MILEAGE,and BODY);both tables...
10
by: jaYPee | last post by:
does anyone experienced slowness when updating a dataset using AcceptChanges? when calling this code it takes many seconds to update the database SqlDataAdapter1.Update(DsStudentCourse1)...
0
by: Mike P | last post by:
I'm updating a datagrid which works fine, but after updating the datagrid does not return to 'view' status, remaining in 'edit' status. Has anybody else had this problem? Thanks, Mike
2
by: Greg | last post by:
I'm using the Framework 1.1, so I don't have access to the new DataGridView object. What I'm wondering is, is there a really simple way to bind a plain datagrid to a database in such a way that...
2
by: marcmc | last post by:
Hey, I have never used a datagrid/dataset/adaptor/table method for updating data, I have always used direct updates to the database so ADO is quite new to me. I have a datagrid and I change a...
0
by: Chet | last post by:
I have a Datagrid that is bound to a Datatable at runtime. I allow the user to select a number of rows using the mouse and then click a button that says "check selected rows", which then cycles...
2
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.