How to persist datatable through form.post?

B

Bill

I am still new at this but I was quite surprised to find that I cannot make
a datatable object survive a repost!

I suppose I could populate and read back a datagrid but that seems messy.

how else can I do this?

Thanks

Bill


Dim cmd As SqlCommand
Dim con As SqlConnection
Dim da As New SqlDataAdapter
Dim dt As DataTable


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

constr =
Web.Configuration.WebConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString
con = New SqlConnection(constr)

If Not Page.IsPostBack Then

cmd = New SqlCommand("stp_GetExternalDest", con)
da.SelectCommand = cmd
da.SelectCommand.Parameters.AddWithValue("@int_CustomerId",
intCustomerID)

da.Fill(ds, "tblExternals")
dt = ds.Tables("tblExternals") '
this does not survive a postback !!!!!!!!!!
 
C

Cor Ligthert [MVP]

Bill,

The most easy one in this is to put it in a Session.Item.

You have 3 other opportunities, but all of them have behaviour you probably
don't want.

Cor
 
B

Bill

Ok so if I really cannot persist the datatable, which is more efficient

1. Session.item
2. HttpContext.item ( not sure if this really any different than 1)
3. Just rerun the database query - simple .stp with max of 50 rows with 5
items per row
4. Use hidden datagrid control fields and read them back after the postback

Thanks

Bill
 
C

Cor Ligthert [MVP]

Bill,
1. Session.item

That is what I did advice you
2. HttpContext.item ( not sure if this really any different than 1)

I only see this as something related to Sharepoint so I do not know what you
mean,
3. Just rerun the database query - simple .stp with max of 50 rows with 5
items per row

And what you do if there has been changes?
4. Use hidden datagrid control fields and read them back after the
postback
One of the four I told about was the "viewstate" which is almost the same,
but that cost you a lot of speed

Cor
 
B

Bill

ok thanks

I will use Session.item

Bill


Cor Ligthert said:
Bill,


That is what I did advice you


I only see this as something related to Sharepoint so I do not know what
you mean,


And what you do if there has been changes?

One of the four I told about was the "viewstate" which is almost the same,
but that cost you a lot of speed

Cor
 

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

Top