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);
 

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

Back
Top