在以下代码中:DWDM是数字,SEX是中文,因此第二个if就报错,怎样改一下?
protected void SqlDataSource3_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.CommandText += " where 1 = 1 ";
        if (DropDownList1.SelectedValue != "0")
            e.Command.CommandText += " and DWDM = " + DropDownList1.SelectedValue;
        if (DropDownList2.SelectedValue != "0")
            e.Command.CommandText += " and SEX = " + DropDownList2.SelectedValue;    }

解决方案 »

  1.   

    e.Command.CommandText += " and SEX = '" + DropDownList2.SelectedValue +"'" ; 
      

  2.   


    protected void SqlDataSource3_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            e.Command.CommandText += " where 1 = 1 ";
            if (DropDownList1.SelectedValue != "0")
                e.Command.CommandText += " and DWDM = ' " + DropDownList1.SelectedValue + " ' ";
            if (DropDownList2.SelectedValue != "0")
                e.Command.CommandText += " and SEX = ' " + DropDownList2.SelectedValue + " ' ";    }
      

  3.   

       e.Command.CommandText += " and SEX = '" + DropDownList2.SelectedValue+"'";