Keeping datatable data in memory

G

Guest

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
 
P

Patrice

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 ?)
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top