declaring/ initializeing variable 2 ways

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KevinRug

    #1

    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("get PersonalInfo", myG.sqlConnecti on);



    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("get PersonalInfo", myG.sqlConnecti on);

    Any ideas on why it behaves differently?

    thanks for any help.




  • KevinRug

    #2
    Re: declaring/ initializeing variable 2 ways

    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("get PersonalInfo", myG.sqlConnecti on);
    should be
    SqlCommand cmdPersonalInfo = new SqlCommand("get PersonalInfo",
    myG.sqlConnecti on);



    "KevinRug" <kevinrug@discu ssions.microsof t.com> wrote in message
    news:e$DmW7HaFH A.1152@tk2msftn gp13.phx.gbl...[color=blue]
    > in one page, i am able to declare and initialize a variable like this, in
    > one line.
    >
    > cmdPersonalInfo = new SqlCommand("get PersonalInfo", myG.sqlConnecti on);
    >
    >
    >
    > 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("get PersonalInfo", myG.sqlConnecti on);
    >
    > Any ideas on why it behaves differently?
    >
    > thanks for any help.
    >
    >
    >
    >[/color]


    Comment

    Working...