Re: Need help with scope (I think)




"UJ" <unclejack@xxxxxxxxxxxx> wrote in message news:481a0482$0$12273$c3e8da3@xxxxxxxxxxxxxxxxxxxx
I have a web form that I am simply dispaying the value(column) from a dataset into a textbox.

Here is the code In the page load event


cmd.Connection = cn
da.SelectCommand = cmd
cmd.CommandText = "Select bhdescription,bhid " & _
"from tBehaviorsTypes " & _
"order by bhid; "
da.Fill(dsBT, "dsBhTypes")
cn.Close()
X = 0

Me.lblBehavior.Text = dsBT.Tables("dsBhTypes").Rows(X).Item"bhDescription").ToString

data adaper, data set, connection and command object are declared as follows

Public ds As New DataSet
Public dsBT As New DataSet
Public cn As New Data.SqlClient.SqlConnection(ConfigurationManager.AppSettings.Get("mCnn"))
Public da As New SqlClient.SqlDataAdapter
Public cmd As New SqlClient.SqlCommand

X is declared as a public in a public module

Everything in the page load appears to work

I've tried running this as a project running on localhost and a website on from the IIS server and get same results.

Any ideas? Thanks!!!!!

The form has a next button which excutes the following code:
X = X + 1
Me.lblBehavior.Text = dsBT.Tables("dsBhTypes").Rows(X).Item("bhDescription").ToString
Me.TextBox1.Text = X.ToString

my problem is that x only increments the first time the next button is clicked not incrementing.

I'll assume that you do know what a Session variable is used for in a Web session. A Web session between the client and the Web server is a stateless session and nothing is held onto like data in variables or whatnot. The server side of the application is started again sort of speaking and everything (variables) are in there initial state each time on the round trip between the client and the Web server. The only way you can keep state with data that is kept in a variable that you want to hold on to that data is to use Session variables.

So X is never going to be incremented because it's always going to be 0 due to a Web session is a stateless session, unlike a Windows Desktop application that keeps state (things held in memory) with the application running on the desktop or laptop computer.

Web server have stateless sessions due to the many clients that the Web server must service at any give point in time. You send data to the Web server from the client and the connection is broken. The Web server sends back data to the client and the connection is broken. The Web server knows nothing about your next session send/receive unless you do coding to tell the Web server to remember you and what you had the last time ,you the client, was in session with the Web server, which is done by keeping Session state.

So, look up what a Session variable is about and how to use one.

BTW, why read the SQL table each time on the round trip if data is not changing in the table between the sessions? Why not hold the data in the table in a session object instead of making the connection to SQL Server and reading the data each time?



.