473,379 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

declaring/ initializeing variable 2 ways

in one page, i am able to declare and initialize a variable like this, in
one line.

cmdPersonalInfo = new SqlCommand("getPersonalInfo", myG.sqlConnection);

In another page it gives me an error when doing as above and I must first
declare then initialize, like so:

SqlCommand cmdPersonalInfo;

cmdPersonalInfo = new SqlCommand("getPersonalInfo", myG.sqlConnection);

Any ideas on why it behaves differently?

thanks for any help.


Jul 21 '05 #1
1 1356
never mind,
I was too tired or frustrated to see the difference.
in one I was trying to use the variable without the type declaration in
front

cmdPersonalInfo = new SqlCommand("getPersonalInfo", myG.sqlConnection);
should be
SqlCommand cmdPersonalInfo = new SqlCommand("getPersonalInfo",
myG.sqlConnection);

"KevinRug" <ke******@discussions.microsoft.com> wrote in message
news:e$**************@tk2msftngp13.phx.gbl...
in one page, i am able to declare and initialize a variable like this, in
one line.

cmdPersonalInfo = new SqlCommand("getPersonalInfo", myG.sqlConnection);

In another page it gives me an error when doing as above and I must first
declare then initialize, like so:

SqlCommand cmdPersonalInfo;

cmdPersonalInfo = new SqlCommand("getPersonalInfo", myG.sqlConnection);

Any ideas on why it behaves differently?

thanks for any help.

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lou zion | last post by:
hi all, i've got a class that takes a parameterless function pointer as a parameter. i want to store that function pointer in a variable and i'm trying to figure out the syntax. i came up with...
16
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
1
by: Maarten Terlingen | last post by:
Sample: ClassA: ClassB ClassB: ClassC ClassA x = new Class C I want to know the declaring type of C. x.GetType() returns C x.GetType().BaseType returns B x.GetType().BaseType.BaseType...
5
by: Brett | last post by:
In a class, I have several Private subs. I declare an instance of the class such as: Dim MySelf as new Class1 within a private sub. The motive is to provide access to other subs within the...
1
by: KevinRug | last post by:
in one page, i am able to declare and initialize a variable like this, in one line. cmdPersonalInfo = new SqlCommand("getPersonalInfo", myG.sqlConnection); In another page it gives me an...
6
by: Mark A. Sam | last post by:
Hello, I am using Visual Web Developer 2005 Express. I want to declare a varible, using Visual Basic as the language and can't get anywhere. For example Public Test1 as String I'll get en...
2
by: pagekb | last post by:
Hello, I'm having some difficulty compiling template classes as containers for other template objects. Specifically, I have a hierarchy of template classes that contain each other. Template...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
8
by: HMS Surprise | last post by:
I looked in the language but did not find a switch for requiring variables to be declared before use. Is such an option available? Thanks, jvh
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.