Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

value of variables disappear

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stefan Bosman - 13 Dec 2007 11:08 GMT
Hi,

when i declare a variable in the "pageload event"  or in the "Partial Class
_default"
my program will recognize the variable but it will loose the value.

example:

Partial Class _Default
   Inherits System.Web.UI.Page
   Dim conStr As String =
ConfigurationManager.ConnectionStrings("connString1").ConnectionString

   order_id = Session("session_orders")
   Dim sqlstr_order As String = "SELECT * FROM Orders WHERE OrdersBaseID="
+ Str(order_id)
   Dim sqladapter_order As New SqlDataAdapter(sqlstr_order, conStr)
   ds_Order.Reset()
   sqladapter_order.Fill(ds_Order, "Orders")

when i use msgbox(sqlstr_order) in an other code it will return  an empty
string and loading data of this table will not work.

example:
               ds_Order.Tables("Orders").Rows(0)("OrderGammaType") + "'"

everything works fine if i copy the code in the other sub every time i need
data from the table.

thanks in advance
(New dot net programmer)
Hans Kesting - 13 Dec 2007 13:31 GMT
Stefan Bosman wrote on 13-12-2007 :
> Hi,
>
[quoted text clipped - 27 lines]
> thanks in advance
> (New dot net programmer)

I think that's because VB tricks you. When you use the same variable
name in some other method (after you have declared it inside some
method) then it is NOT the same variable but an inplicitly declared one
that has no relation whatsoever to the first one.
I think there is an "option strict" you can set somewhere to disable
this behaviour, so you can catch errors like this.

A variable declared inside some method is local to that method
(=unknown outside it). One solution is to declare that variable at
class level and set the value inside a Page_Load (or some other method
that is always executed before you want to use it).

Hans Kesting

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.