Need help with scope (I think)

U

UJ

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.


--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
 
M

Mr. Arnold

UJ said:
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?
 
M

Mr. Arnold

brian said:
Well actually I am not aware of session variables, hence the question to
the group:)

Secondly, and I have no explantion as to why, but it started working. So
am I to understand
that creating a public variable in a public module is a session varible?
If not I am completely
perplexed why code that was not eecuting in the first half of my day,
suddenly started working.

That's not a good way of doing things in Web applications. That is have a
Public variable in a public module. It's a security risk/issue in the Web
application that's facing the public Internet.
I even more complexed since your response would imply what I did was not a
session variable.

No that's not a session variable and it's a bad usage with a Web
application.
None-the less you have given me something to check on. Thanks for your
help and time!!!!!

You should check-out what a .Net State server is about in .Net Web
applications are about.
 
C

Cor Ligthert[MVP]

UJ,.

There is not so much you have to add.

In the pageload event (form load), you set

If IsPostBack then
X = Session.Item("X")
End If

And after your Fill
Session.Item("X") = 0

Just done here in this message so you can get errors

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