日期:2014-05-18  浏览次数:20400 次

10分帮我改个错。。。。。
public   void   dropbind1()
        {    
                SqlConnection   myConnection   =   new   SqlConnection(myConnectionString);
                if   (Convert.ToInt32(Session[ "login_power "])   ==   1)
                {
                        string   sql   =   "select     *       from     gw_address   where   addressname=…… ";
                }
                else
                {
                        string   sql   =   "select     *       from     gw_address   ";
                }
                SqlDataAdapter   custDA   =   new   SqlDataAdapter(sql,   myConnection);
                DataSet   custDS   =   new   DataSet();
                custDA.Fill(custDS);
                DropDownListaddress.DataSource   =   custDS.Tables[0];
                DropDownListaddress.DataTextField   =   "addressname ";
                DropDownListaddress.DataValueField   =   "addressid ";
                DropDownListaddress.DataBind();
                this.DropDownListaddress.Items.Insert(0,   new   ListItem( "请选择地区 ",   "-1 "));
        }

为什么这么写。
我string   的sql没有用?
提示我:当前上下文中不存在名称“sql”
怎么连找都找不到?????????????????????
错在哪?????


------解决方案--------------------
if (Convert.ToInt32(Session[ "login_power "]) == 1)
{
string sql = "select * from gw_address where addressname=…… ";
}
else
{
string sql = "select * from gw_address ";
}

--------------------------------------------
string sql = "select * from gw_address ";

if (Convert.ToInt32(Session[ "login_power "]) == 1)
{
sql = "select * from gw_address where addressname=…… ";
}

------解决方案--------------------
请翻书理解 变量作用域

if (Convert.ToInt32(Session[ "login_power "]) == 1)
{
string sql = "select * from gw_address where addressname=…… ";
}
else
{
string sql = "select * from gw_address ";
}

> > > >

string sql = null;
if (Convert.ToInt32(Session[ "login_power "]) == 1)
{
sql = "select * from gw_address where addressname=…… ";
}
else
{
sql = "select * from gw_address ";