473,508 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

storing problem

Hi,

I'm developping an asp.net application and i ran to the following problem.
When i press an add button in the aspx page I want to store date in an
datatable. The datatable is created in a seperated class, but every time I
click the button only the last item I added is in that table.
Is this because on the button click a new object of the class is created on
every button click? Is there anyone who could help me to fix the problem?
How can I store the info in the class??

aspx-file

private Tabelletje t = new Tabelletje();

private void Button1_Click(object sender, System.EventArgs e)

{

this.DataGrid1.DataSource =
t.insertResoureInDataTable(Int32.Parse(this.TextBo x1.Text),Int32.Parse(this.
TextBox2.Text));

this.DataGrid1.DataBind();

}

class

public class Tabelletje

{

private DataSet ds;

private DataTable table;

private DataColumn col;

private DataRow row;

public Tabelletje()

{

this.createDataTableResources();

}

public void createDataTableResources()

{

ds = new DataSet();

table = new DataTable("test");

col = new DataColumn();

col.DataType = System.Type.GetType("System.Int32");

col.ColumnName = "resID";

table.Columns.Add(col);

col = new DataColumn();

col.DataType = System.Type.GetType("System.Int32");

col.ColumnName = "evrAantal";

table.Columns.Add(col);

ds.Tables.Add(table);

}

public DataSet insertResoureInDataTable(int resID, int aantal)

{

row = table.NewRow();

row["resID"] = resID;

row["evrAantal"] = aantal;

table.Rows.Add(row);

return ds;

}

}
thx
Nov 18 '05 #1
2 1022
Every PostBack means that each and every class in a Page has to be
re-created on the server. Therefore, if you add to a DataTable during one
PostBack, you have to add again with each successive PostBack. Look at some
of the server-side caching alternatives for a solution.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Andy Cortvriend" <an*************@student.kahosl.be> wrote in message
news:c0**********@ikaria.belnet.be...
Hi,

I'm developping an asp.net application and i ran to the following problem.
When i press an add button in the aspx page I want to store date in an
datatable. The datatable is created in a seperated class, but every time I
click the button only the last item I added is in that table.
Is this because on the button click a new object of the class is created on every button click? Is there anyone who could help me to fix the problem?
How can I store the info in the class??

aspx-file

private Tabelletje t = new Tabelletje();

private void Button1_Click(object sender, System.EventArgs e)

{

this.DataGrid1.DataSource =
t.insertResoureInDataTable(Int32.Parse(this.TextBo x1.Text),Int32.Parse(this. TextBox2.Text));

this.DataGrid1.DataBind();

}

class

public class Tabelletje

{

private DataSet ds;

private DataTable table;

private DataColumn col;

private DataRow row;

public Tabelletje()

{

this.createDataTableResources();

}

public void createDataTableResources()

{

ds = new DataSet();

table = new DataTable("test");

col = new DataColumn();

col.DataType = System.Type.GetType("System.Int32");

col.ColumnName = "resID";

table.Columns.Add(col);

col = new DataColumn();

col.DataType = System.Type.GetType("System.Int32");

col.ColumnName = "evrAantal";

table.Columns.Add(col);

ds.Tables.Add(table);

}

public DataSet insertResoureInDataTable(int resID, int aantal)

{

row = table.NewRow();

row["resID"] = resID;

row["evrAantal"] = aantal;

table.Rows.Add(row);

return ds;

}

}
thx

Nov 18 '05 #2
thx

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:ee*************@tk2msftngp13.phx.gbl...
Every PostBack means that each and every class in a Page has to be
re-created on the server. Therefore, if you add to a DataTable during one
PostBack, you have to add again with each successive PostBack. Look at some of the server-side caching alternatives for a solution.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Andy Cortvriend" <an*************@student.kahosl.be> wrote in message
news:c0**********@ikaria.belnet.be...
Hi,

I'm developping an asp.net application and i ran to the following problem. When i press an add button in the aspx page I want to store date in an
datatable. The datatable is created in a seperated class, but every time I click the button only the last item I added is in that table.
Is this because on the button click a new object of the class is created

on
every button click? Is there anyone who could help me to fix the problem? How can I store the info in the class??

aspx-file

private Tabelletje t = new Tabelletje();

private void Button1_Click(object sender, System.EventArgs e)

{

this.DataGrid1.DataSource =

t.insertResoureInDataTable(Int32.Parse(this.TextBo x1.Text),Int32.Parse(this.
TextBox2.Text));

this.DataGrid1.DataBind();

}

class

public class Tabelletje

{

private DataSet ds;

private DataTable table;

private DataColumn col;

private DataRow row;

public Tabelletje()

{

this.createDataTableResources();

}

public void createDataTableResources()

{

ds = new DataSet();

table = new DataTable("test");

col = new DataColumn();

col.DataType = System.Type.GetType("System.Int32");

col.ColumnName = "resID";

table.Columns.Add(col);

col = new DataColumn();

col.DataType = System.Type.GetType("System.Int32");

col.ColumnName = "evrAantal";

table.Columns.Add(col);

ds.Tables.Add(table);

}

public DataSet insertResoureInDataTable(int resID, int aantal)

{

row = table.NewRow();

row["resID"] = resID;

row["evrAantal"] = aantal;

table.Rows.Add(row);

return ds;

}

}
thx


Nov 18 '05 #3

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

Similar topics

2
1756
by: Francisco | last post by:
I have this problem: I have a database with information about games, and users are able to vote for them. Everytime a user votes for a game I store the unique game name into a session variable (an...
3
11737
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
4
3857
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
8
10472
by: Daniel | last post by:
I'm trying to make a site work for japanese characters. It works fine except for the alerts in javascript. The characters are stored in unicode, as this; 'コミック全巻配' Those unicode characters...
2
1797
by: Robert | last post by:
I have no problem storing dates + times in a System.DateTime object. In addition, it's easy to output a Time as a string from an existing Date/Time. But I'm having trouble storing a time only. ...
6
2552
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
5
2124
by: Don Vaillancourt | last post by:
I'm building a system when one can upload a document to the website. I will be storing the document on the hard-drive for quick/easy access, but I was also thinking of storing it in an existing...
6
3038
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a...
4
2714
by: Rednelle | last post by:
Greetings all, As a newbie, using Access 2000, I would appreciate advice on the best way to include pictures. I have developed a 'Home Inventory' database which can include jpeg thumbnails of...
1
2803
by: None | last post by:
Hi, I have developed webshop application using asp.net 1.1. I'm using DataGrid in one of the pages of my site. During the page load the DataGrid will be binded by around 7500 products(rows). At...
0
7225
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
7124
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
7326
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
7385
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
5629
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,...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.