473,395 Members | 1,649 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,395 software developers and data experts.

using a datagrid in asp.net

I have a datagrid that I am trying to add rows to on a page. I have several
textboxes that allow data entry for each column in the data grid and a button
that submits the data by refilling the datagrid's datasource (after the new
data is saved in the database) and databinding the datagrid. When I place a
breakpoint at the method used for filling the datasource and walk through the
code, the code works and the datagrid displays the new row of data. However,
when I remove the breakpoint and execute the code without any stops, the
datagrid does not display the new row. Any suggestions on what may be going
on here?
Thanks in advance
Lance
Jul 21 '05 #1
4 1300
Lance, can you post the code...

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Lance" <La***@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
I have a datagrid that I am trying to add rows to on a page. I have several textboxes that allow data entry for each column in the data grid and a button that submits the data by refilling the datagrid's datasource (after the new data is saved in the database) and databinding the datagrid. When I place a breakpoint at the method used for filling the datasource and walk through the code, the code works and the datagrid displays the new row of data. However, when I remove the breakpoint and execute the code without any stops, the
datagrid does not display the new row. Any suggestions on what may be going on here?
Thanks in advance
Lance

Jul 21 '05 #2
I update the database table and then call FillPrintData() and then
BindDataGrid().

private void BindDataGrid()
{
dgPrints.CurrentPageIndex =
Convert.ToInt32(Session["PageIndex"]);
dgPrints.DataSource = (DataTable)Session["DataTable"];
dgPrints.DataBind();
}
private void FillPrintData()
{

string strSQL = "SELECT PrintTable.Print_ID, PrintTable.Photo_ID,
PrintTable.Print_Size, PrintTable.Print_Price, PrintTable.Print_Poster FROM
PrintTable "
+ "WHERE PrintTable.Photo_ID =" + Photo_ID
+ " ORDER BY Print_ID Desc";
OleDbCommand cmd;
OleDbConnection cnn = null;
OleDbDataReader dr = null;
dt = new DataTable();
DataRow darow;
//try
//{
cnn = new OleDbConnection(
ConfigurationSettings.AppSettings["AccessConnectionString"]);
cnn.Open();
cmd = new OleDbCommand(strSQL, cnn);
dr = cmd.ExecuteReader();

// Fill in data.
dt.Columns.Add(new DataColumn(
"C0", typeof(string )));
dt.Columns.Add(new DataColumn(
"C1", typeof(string )));
dt.Columns.Add(new DataColumn(
"C2", typeof(string )));
dt.Columns.Add(new DataColumn(
"C3", typeof(double )));
dt.Columns.Add(new DataColumn(
"C4", typeof(string )));
// Loop through all the rows, retrieving the
// columns you need. Also look into the GetString
// method (and other get... methods) for a faster
// way to retrieve individual columns.
while (dr.Read())
{
darow = dt.NewRow();
darow[0] = dr[0].ToString();
darow[1] = dr[1].ToString();
darow[2] = dr[2].ToString();
darow[3] = dr[3].ToString();
darow[4] = dr[4].ToString();
dt.Rows.Add(darow);

//lblError.Text = "This";
//lstResults.Items.Add(String.Format("{0} {1}: {2}",
// dr[0].ToString(), dr[1].ToString(), dr[2].ToString()));
}
Session["DataTable"] = dt;
//mdv = new DataView(dt);
//return mdv;
}
Jul 21 '05 #3
Primarily it looks like you aren't closing the connection - very bad. If
you're trying to fill a datatable, why not just call
DataAdapter.Fill(DataTable);?For what you're doing, you get 0 benefit by
using a reader and you have to write a lot more code. Also, you really
ought ot paramaterize that query... it's better in every respect.

Let me know if either setting the Closeconnection enum in your call to
executeReader or adding a close in a try/catch/finally doesn't fix it.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Lance" <La***@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
I update the database table and then call FillPrintData() and then
BindDataGrid().

private void BindDataGrid()
{
dgPrints.CurrentPageIndex =
Convert.ToInt32(Session["PageIndex"]);
dgPrints.DataSource = (DataTable)Session["DataTable"];
dgPrints.DataBind();
}
private void FillPrintData()
{

string strSQL = "SELECT PrintTable.Print_ID, PrintTable.Photo_ID,
PrintTable.Print_Size, PrintTable.Print_Price, PrintTable.Print_Poster FROM PrintTable "
+ "WHERE PrintTable.Photo_ID =" + Photo_ID
+ " ORDER BY Print_ID Desc";
OleDbCommand cmd;
OleDbConnection cnn = null;
OleDbDataReader dr = null;
dt = new DataTable();
DataRow darow;
//try
//{
cnn = new OleDbConnection(
ConfigurationSettings.AppSettings["AccessConnectionString"]);
cnn.Open();
cmd = new OleDbCommand(strSQL, cnn);
dr = cmd.ExecuteReader();

// Fill in data.
dt.Columns.Add(new DataColumn(
"C0", typeof(string )));
dt.Columns.Add(new DataColumn(
"C1", typeof(string )));
dt.Columns.Add(new DataColumn(
"C2", typeof(string )));
dt.Columns.Add(new DataColumn(
"C3", typeof(double )));
dt.Columns.Add(new DataColumn(
"C4", typeof(string )));
// Loop through all the rows, retrieving the
// columns you need. Also look into the GetString
// method (and other get... methods) for a faster
// way to retrieve individual columns.
while (dr.Read())
{
darow = dt.NewRow();
darow[0] = dr[0].ToString();
darow[1] = dr[1].ToString();
darow[2] = dr[2].ToString();
darow[3] = dr[3].ToString();
darow[4] = dr[4].ToString();
dt.Rows.Add(darow);

//lblError.Text = "This";
//lstResults.Items.Add(String.Format("{0} {1}: {2}",
// dr[0].ToString(), dr[1].ToString(), dr[2].ToString()));
}
Session["DataTable"] = dt;
//mdv = new DataView(dt);
//return mdv;
}

Jul 21 '05 #4
W.G.
Thanks for your response. I closed the connection on the Reader like you
mentioned and I still am having the same results. (I Actually had the
Try/Catch/Finally which closed the objects commented out in my original
code). I then changed the code to include in my dataset the table being used
to populate the grid and then used the .fill method (instead of the Reader).
Still the same results. Both scenarios will work if I walk though the code,
but if I run it without breaking, the grid does not refresh with the new Row.
Very confusing.
Also, What do you mean by "paramaterize that query"? Example
Thanks Again
Lance

"W.G. Ryan eMVP" wrote:
Primarily it looks like you aren't closing the connection - very bad. If
you're trying to fill a datatable, why not just call
DataAdapter.Fill(DataTable);?For what you're doing, you get 0 benefit by
using a reader and you have to write a lot more code. Also, you really
ought ot paramaterize that query... it's better in every respect.

Let me know if either setting the Closeconnection enum in your call to
executeReader or adding a close in a try/catch/finally doesn't fix it.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Lance" <La***@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
I update the database table and then call FillPrintData() and then
BindDataGrid().

private void BindDataGrid()
{
dgPrints.CurrentPageIndex =
Convert.ToInt32(Session["PageIndex"]);
dgPrints.DataSource = (DataTable)Session["DataTable"];
dgPrints.DataBind();
}
private void FillPrintData()
{

string strSQL = "SELECT PrintTable.Print_ID, PrintTable.Photo_ID,
PrintTable.Print_Size, PrintTable.Print_Price, PrintTable.Print_Poster

FROM
PrintTable "
+ "WHERE PrintTable.Photo_ID =" + Photo_ID
+ " ORDER BY Print_ID Desc";
OleDbCommand cmd;
OleDbConnection cnn = null;
OleDbDataReader dr = null;
dt = new DataTable();
DataRow darow;
//try
//{
cnn = new OleDbConnection(
ConfigurationSettings.AppSettings["AccessConnectionString"]);
cnn.Open();
cmd = new OleDbCommand(strSQL, cnn);
dr = cmd.ExecuteReader();

// Fill in data.
dt.Columns.Add(new DataColumn(
"C0", typeof(string )));
dt.Columns.Add(new DataColumn(
"C1", typeof(string )));
dt.Columns.Add(new DataColumn(
"C2", typeof(string )));
dt.Columns.Add(new DataColumn(
"C3", typeof(double )));
dt.Columns.Add(new DataColumn(
"C4", typeof(string )));
// Loop through all the rows, retrieving the
// columns you need. Also look into the GetString
// method (and other get... methods) for a faster
// way to retrieve individual columns.
while (dr.Read())
{
darow = dt.NewRow();
darow[0] = dr[0].ToString();
darow[1] = dr[1].ToString();
darow[2] = dr[2].ToString();
darow[3] = dr[3].ToString();
darow[4] = dr[4].ToString();
dt.Rows.Add(darow);

//lblError.Text = "This";
//lstResults.Items.Add(String.Format("{0} {1}: {2}",
// dr[0].ToString(), dr[1].ToString(), dr[2].ToString()));
}
Session["DataTable"] = dt;
//mdv = new DataView(dt);
//return mdv;
}


Jul 21 '05 #5

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

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
0
by: Dave | last post by:
Tried posting in the Winform Forum without much luck, so posting here... After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is...
2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
2
by: Andy Fish | last post by:
Hi, I have some data which is stored as an array (or possibly an arraylist) of identically typed objects, each of which has certain public properties. I want to display these in a datagrid...
2
by: Axel Dahmen | last post by:
Hi, I'm using a DataGrid control to show a table's content with paging. For navigation through the pages I'm using the DataGrid's intrinsic navigation section. My problem: The DataGrid...
12
by: TB | last post by:
Hi All: I am trying to create a variation on the standard datagrid, whereby the datagrid is only shown after pressing some buttons. This reason for this is that I would like to use the same...
1
by: kingster | last post by:
Hi, I have a regular dataset and all i want to do is make a pivot table display in a browser with the datasource of the pivot table to be this dataset and then the end-user will be able to do...
0
by: pedaammulu | last post by:
Hi All, New title for Mastering Web Application Development. All secrets of developing an Accounting Software for the web revealed. Title: "Develop your own Web Accounting Application...
3
by: rn5a | last post by:
A SqlDataReader is populated with the records from a SQL Server 2005 DB table. The records retrieved depends upon 2 conditions (the conditions depend on what a user selects in an ASPX page). If...
1
nateraaaa
by: nateraaaa | last post by:
While working on a recent project I discovered how useful the CommandArgument property can be. I needed to determine the record_id of a row displayed in my datagrid. When the user clicked the Edit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.