473,378 Members | 1,390 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,378 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 1299
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.