如下代码:
private void Page_Load(object sender, System.EventArgs e)
{
sf=Request["sf"];
         //属性StrSql
StrSql="select id,coName from CompanyTable where coname like '%"+TextBox1.Text+"%'";
Bind(sf);        //这时sf是空的
}private void Bind(string sql)
{
         ......
         //方法体中要调用的变量和属性StrSql一样
SqlCommand cmd=new SqlCommand(""+StrSql+"",conn);
         ......
}//属性StrSql
private string StrSql
{
get
{
return (String)ViewState["StrSql"];
}
set
{
ViewState["StrSql"] = value;
}
}大家说我这样调用Bind(sf);方法Bind的时候会不会出错?结果是没出错,因为SqlCommand cmd=new SqlCommand(""+StrSql+"",conn);中的StrSql变成了select id,coName from CompanyTable where coname like '%"+TextBox1.Text+"%',这是怎么回事?
按理说sf是空的,Bind(sf)这样的时候方法体中的""+StrSql+""应该被赋予了空值吧?