473,386 Members | 2,114 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,386 software developers and data experts.

Keeping datatable data in memory

Hi, I wonder if anyone can help?

I've got a web form (intranet), .net version 1.1. I've got a sub that
populates a datatable in a dataset, dependent on a dropdown field selection.
This works great, but if the user selects another item from the dropdown
field and the sub runs again, the original data is overwritten. How do I
store the original data and add the new datarow without overwriting the
original? Here's my code:

Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents DS As System.Data.DataSet
Protected WithEvents UsersTable As System.Data.DataTable
Protected WithEvents UserIDColumn As System.Data.DataColumn
Protected WithEvents NameColumn As System.Data.DataColumn
Protected WithEvents EmailColumn As System.Data.DataColumn
Private workRow As DataRow

Private Sub SelectPeopleBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SelectPeopleBtn.Click
'add the selected person to the email list
Dim IDEmail As String = Me.IndividualsDD.SelectedValue
Dim userFullName As String = Me.IndividualsDD.SelectedItem.Text
'the idemail value comprises of the id and the email address so
we need to split them out
Dim stringLength As Integer = IDEmail.Length
Dim commaPos As Integer = IDEmail.IndexOf(",")
Dim email As String = IDEmail.Substring(commaPos + 1)
Dim id As String = Left(IDEmail, commaPos)
'now we have the person's email, id and name we can put them in
the required places
workRow = Me.DS.Tables("Users").NewRow
workRow(0) = id
workRow(1) = userFullName
workRow(2) = email
Me.DS.Tables("Users").Rows.Add(workRow)
Me.DS.AcceptChanges()
Me.DataGrid.DataBind()
'now remove the selected person from the drop down list so they
can't be selected again
Me.IndividualsDD.SelectedValue = "--"
Me.IndividualsDD.Items.Remove(IDEmail)
Me.IndividualsDD.DataBind()
End Sub

Thanks in advance
Julia
Oct 30 '07 #1
5 3736
I don't understand how existing DataRows can be overwritten, because this code:

workRow = Me.DS.Tables("Users").NewRow

--creates and adds a new DataRow each time. Can you explain?
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Julia B" wrote:
Hi, I wonder if anyone can help?

I've got a web form (intranet), .net version 1.1. I've got a sub that
populates a datatable in a dataset, dependent on a dropdown field selection.
This works great, but if the user selects another item from the dropdown
field and the sub runs again, the original data is overwritten. How do I
store the original data and add the new datarow without overwriting the
original? Here's my code:

Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents DS As System.Data.DataSet
Protected WithEvents UsersTable As System.Data.DataTable
Protected WithEvents UserIDColumn As System.Data.DataColumn
Protected WithEvents NameColumn As System.Data.DataColumn
Protected WithEvents EmailColumn As System.Data.DataColumn
Private workRow As DataRow

Private Sub SelectPeopleBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SelectPeopleBtn.Click
'add the selected person to the email list
Dim IDEmail As String = Me.IndividualsDD.SelectedValue
Dim userFullName As String = Me.IndividualsDD.SelectedItem.Text
'the idemail value comprises of the id and the email address so
we need to split them out
Dim stringLength As Integer = IDEmail.Length
Dim commaPos As Integer = IDEmail.IndexOf(",")
Dim email As String = IDEmail.Substring(commaPos + 1)
Dim id As String = Left(IDEmail, commaPos)
'now we have the person's email, id and name we can put them in
the required places
workRow = Me.DS.Tables("Users").NewRow
workRow(0) = id
workRow(1) = userFullName
workRow(2) = email
Me.DS.Tables("Users").Rows.Add(workRow)
Me.DS.AcceptChanges()
Me.DataGrid.DataBind()
'now remove the selected person from the drop down list so they
can't be selected again
Me.IndividualsDD.SelectedValue = "--"
Me.IndividualsDD.Items.Remove(IDEmail)
Me.IndividualsDD.DataBind()
End Sub

Thanks in advance
Julia
Oct 30 '07 #2
P.S.
Probably what's happening here is that you aren't storing your DataSet
between postbacks, so the whole thing is getting recreated. Store the DataSet
in Session,
and check for it's existence in the beginning of your method.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Julia B" wrote:
Hi, I wonder if anyone can help?

I've got a web form (intranet), .net version 1.1. I've got a sub that
populates a datatable in a dataset, dependent on a dropdown field selection.
This works great, but if the user selects another item from the dropdown
field and the sub runs again, the original data is overwritten. How do I
store the original data and add the new datarow without overwriting the
original? Here's my code:

Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents DS As System.Data.DataSet
Protected WithEvents UsersTable As System.Data.DataTable
Protected WithEvents UserIDColumn As System.Data.DataColumn
Protected WithEvents NameColumn As System.Data.DataColumn
Protected WithEvents EmailColumn As System.Data.DataColumn
Private workRow As DataRow

Private Sub SelectPeopleBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SelectPeopleBtn.Click
'add the selected person to the email list
Dim IDEmail As String = Me.IndividualsDD.SelectedValue
Dim userFullName As String = Me.IndividualsDD.SelectedItem.Text
'the idemail value comprises of the id and the email address so
we need to split them out
Dim stringLength As Integer = IDEmail.Length
Dim commaPos As Integer = IDEmail.IndexOf(",")
Dim email As String = IDEmail.Substring(commaPos + 1)
Dim id As String = Left(IDEmail, commaPos)
'now we have the person's email, id and name we can put them in
the required places
workRow = Me.DS.Tables("Users").NewRow
workRow(0) = id
workRow(1) = userFullName
workRow(2) = email
Me.DS.Tables("Users").Rows.Add(workRow)
Me.DS.AcceptChanges()
Me.DataGrid.DataBind()
'now remove the selected person from the drop down list so they
can't be selected again
Me.IndividualsDD.SelectedValue = "--"
Me.IndividualsDD.Items.Remove(IDEmail)
Me.IndividualsDD.DataBind()
End Sub

Thanks in advance
Julia
Oct 30 '07 #3
Are you familiar with the web development model ? Keep in mind that your
page lives just during the HTTP request.

How do you initialize your datatable ? For now my thought would be that you
get the data from the db than add a new row in this procedure.

When the user does a change and postback again you does the same thing. As a
result the new row is never added to the db. You just get the same data
again and again and you add a "new" single new row each time to the
datatable (without updating the underlying DB ?)

--
Patrice
"Julia B" <Ju****@discussions.microsoft.coma écrit dans le message de
news: 30**********************************@microsoft.com...
Hi, I wonder if anyone can help?

I've got a web form (intranet), .net version 1.1. I've got a sub that
populates a datatable in a dataset, dependent on a dropdown field
selection.
This works great, but if the user selects another item from the dropdown
field and the sub runs again, the original data is overwritten. How do I
store the original data and add the new datarow without overwriting the
original? Here's my code:

Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents DS As System.Data.DataSet
Protected WithEvents UsersTable As System.Data.DataTable
Protected WithEvents UserIDColumn As System.Data.DataColumn
Protected WithEvents NameColumn As System.Data.DataColumn
Protected WithEvents EmailColumn As System.Data.DataColumn
Private workRow As DataRow

Private Sub SelectPeopleBtn_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles SelectPeopleBtn.Click
'add the selected person to the email list
Dim IDEmail As String = Me.IndividualsDD.SelectedValue
Dim userFullName As String = Me.IndividualsDD.SelectedItem.Text
'the idemail value comprises of the id and the email address so
we need to split them out
Dim stringLength As Integer = IDEmail.Length
Dim commaPos As Integer = IDEmail.IndexOf(",")
Dim email As String = IDEmail.Substring(commaPos + 1)
Dim id As String = Left(IDEmail, commaPos)
'now we have the person's email, id and name we can put them in
the required places
workRow = Me.DS.Tables("Users").NewRow
workRow(0) = id
workRow(1) = userFullName
workRow(2) = email
Me.DS.Tables("Users").Rows.Add(workRow)
Me.DS.AcceptChanges()
Me.DataGrid.DataBind()
'now remove the selected person from the drop down list so they
can't be selected again
Me.IndividualsDD.SelectedValue = "--"
Me.IndividualsDD.Items.Remove(IDEmail)
Me.IndividualsDD.DataBind()
End Sub

Thanks in advance
Julia

Oct 30 '07 #4
Hi, that's my problem really. I am new to web development and am actually
going on a proper training course in a couple of weeks. I'm learning as I go
on this one!

My data is not being stored in a database. I'm actually very familiar with
ado.net and storing and retrieving data from a db, so I don't have a problem
with that. This is data being stored in a web session datatable.

Julia

"Patrice" wrote:
Are you familiar with the web development model ? Keep in mind that your
page lives just during the HTTP request.

How do you initialize your datatable ? For now my thought would be that you
get the data from the db than add a new row in this procedure.

When the user does a change and postback again you does the same thing. As a
result the new row is never added to the db. You just get the same data
again and again and you add a "new" single new row each time to the
datatable (without updating the underlying DB ?)

--
Patrice
"Julia B" <Ju****@discussions.microsoft.coma écrit dans le message de
news: 30**********************************@microsoft.com...
Hi, I wonder if anyone can help?

I've got a web form (intranet), .net version 1.1. I've got a sub that
populates a datatable in a dataset, dependent on a dropdown field
selection.
This works great, but if the user selects another item from the dropdown
field and the sub runs again, the original data is overwritten. How do I
store the original data and add the new datarow without overwriting the
original? Here's my code:

Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents DS As System.Data.DataSet
Protected WithEvents UsersTable As System.Data.DataTable
Protected WithEvents UserIDColumn As System.Data.DataColumn
Protected WithEvents NameColumn As System.Data.DataColumn
Protected WithEvents EmailColumn As System.Data.DataColumn
Private workRow As DataRow

Private Sub SelectPeopleBtn_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles SelectPeopleBtn.Click
'add the selected person to the email list
Dim IDEmail As String = Me.IndividualsDD.SelectedValue
Dim userFullName As String = Me.IndividualsDD.SelectedItem.Text
'the idemail value comprises of the id and the email address so
we need to split them out
Dim stringLength As Integer = IDEmail.Length
Dim commaPos As Integer = IDEmail.IndexOf(",")
Dim email As String = IDEmail.Substring(commaPos + 1)
Dim id As String = Left(IDEmail, commaPos)
'now we have the person's email, id and name we can put them in
the required places
workRow = Me.DS.Tables("Users").NewRow
workRow(0) = id
workRow(1) = userFullName
workRow(2) = email
Me.DS.Tables("Users").Rows.Add(workRow)
Me.DS.AcceptChanges()
Me.DataGrid.DataBind()
'now remove the selected person from the drop down list so they
can't be selected again
Me.IndividualsDD.SelectedValue = "--"
Me.IndividualsDD.Items.Remove(IDEmail)
Me.IndividualsDD.DataBind()
End Sub

Thanks in advance
Julia


Oct 31 '07 #5
Hi, I'm new to web development. I'm very familiar with ADO.net and storing
and retrieving data from dbs, but not when it comes to web sessions. I'm
actually going on a training course in a couple of weeks, but in the
meantime, I'm learning as I go on this one.

How do you store a dataset then?

Julai

"Peter Bromberg [C# MVP]" wrote:
P.S.
Probably what's happening here is that you aren't storing your DataSet
between postbacks, so the whole thing is getting recreated. Store the DataSet
in Session,
and check for it's existence in the beginning of your method.
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Julia B" wrote:
Hi, I wonder if anyone can help?

I've got a web form (intranet), .net version 1.1. I've got a sub that
populates a datatable in a dataset, dependent on a dropdown field selection.
This works great, but if the user selects another item from the dropdown
field and the sub runs again, the original data is overwritten. How do I
store the original data and add the new datarow without overwriting the
original? Here's my code:

Protected WithEvents DataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents DS As System.Data.DataSet
Protected WithEvents UsersTable As System.Data.DataTable
Protected WithEvents UserIDColumn As System.Data.DataColumn
Protected WithEvents NameColumn As System.Data.DataColumn
Protected WithEvents EmailColumn As System.Data.DataColumn
Private workRow As DataRow

Private Sub SelectPeopleBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles SelectPeopleBtn.Click
'add the selected person to the email list
Dim IDEmail As String = Me.IndividualsDD.SelectedValue
Dim userFullName As String = Me.IndividualsDD.SelectedItem.Text
'the idemail value comprises of the id and the email address so
we need to split them out
Dim stringLength As Integer = IDEmail.Length
Dim commaPos As Integer = IDEmail.IndexOf(",")
Dim email As String = IDEmail.Substring(commaPos + 1)
Dim id As String = Left(IDEmail, commaPos)
'now we have the person's email, id and name we can put them in
the required places
workRow = Me.DS.Tables("Users").NewRow
workRow(0) = id
workRow(1) = userFullName
workRow(2) = email
Me.DS.Tables("Users").Rows.Add(workRow)
Me.DS.AcceptChanges()
Me.DataGrid.DataBind()
'now remove the selected person from the drop down list so they
can't be selected again
Me.IndividualsDD.SelectedValue = "--"
Me.IndividualsDD.Items.Remove(IDEmail)
Me.IndividualsDD.DataBind()
End Sub

Thanks in advance
Julia
Oct 31 '07 #6

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

Similar topics

5
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the...
6
by: Mountain Bikn' Guy | last post by:
When one gets a row from a database (ie, a DataTable), the row contains a typed value in each column. How is this typically implemented behind scenes. I want to build this functionality myself. The...
1
by: VMI | last post by:
Is it possible to store the data in a datatable in the hard disk instead of the memory? By default, when a datatable's being filled, the table (and data) will remain in memory. Would it be possible...
9
by: VMI | last post by:
We have this huge application that's based on storing tons of data on a dataTable. The only problem we're having is that storing LOTS of data (1 million records) into a datatable will slow down the...
8
by: ZeroVisio | last post by:
Hi, I want to know if there is an easy way to do update a column of a row in DataTable.
2
by: ven | last post by:
Hello i have a dynamic datatable in my page. I wanna to write data to textboxes and after click on button "ADD data" i want to refresh datagrid on page... Here is my code : ' Insert page code...
1
by: BStrick | last post by:
I would like to know what may be the "Best" way to approach with problem. I have an application that I created to transfers data dynamically from an unknown source (ie maybe Excel, Access, XML,...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
5
by: jehugaleahsa | last post by:
Hello: What is the point of using a DataTable in ASP .NET? We are unsure how you can use them without 1) rebuilding them every postback, or 2) taking up precious memory. We are not sure how to...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.