declaring/ initializeing variable 2 ways

  • Thread starter Thread starter KevinRug
  • Start date Start date
K

KevinRug

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.
 
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);
 
Back
Top