谁帮我看看这是什么问题啊??数据库的
public void BindGrid()
{
string strconn = ConfigurationSettings.AppSettings[ "dsn "];
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
string mysql = "select * from Projects,Client,Contract where TCID=CID AND TPID=PID ";
if (ddl_tcid.SelectedItem.Value.ToString()!= "0 ")
{
mysql=mysql+ "and TCID= ' "+ddl_tcid.SelectedItem.Value.ToString()+ " ' ";
}
if (ddl_tpid.SelectedItem.Value.ToString()!= "0 ")
{
mysql=mysql+ "and TPID= ' "+ddl_tpid.SelectedItem.Value.ToString()+ " ' ";
}
if (ddl_tstate.SelectedItem.Value.ToString()!= "0 ")
{
mysql = mysql + "and TState= ' " + ddl_tstate.SelectedItem.Value.ToString() + " ' ";
}
mysql = mysql + "order by TState,TEndDate ";
SqlDataAdapter da = new SqlDataAdapter(mysql, cn);
DataSet ds = new DataSet();
da.Fill(ds);
dgd_contractlist.DataSource = ds;
dgd_contractlist.DataBind();
cn.Close();
}
提示说 用户代码未处理 sqlexception 第一行tcid附近有语法错误 这可能是什么问题啊??????????sql语句哪里错了啊?
[解决办法]
if (ddl_tcid.SelectedItem.Value.ToString()!= "0 ")
{
mysql=mysql+ "and TCID= ' "+ddl_tcid.SelectedItem.Value.ToString()+ " ' ";//空格被你吃掉了
}
if (ddl_tpid.SelectedItem.Value.ToString()!= "0 ")
{
mysql=mysql+ "and TPID= ' "+ddl_tpid.SelectedItem.Value.ToString()+ " ' ";//空格被你吃掉了
}
if (ddl_tstate.SelectedItem.Value.ToString()!= "0 ")
{
mysql = mysql + "and TState= ' " + ddl_tstate.SelectedItem.Value.ToString() + " ' ";//空格被你吃掉了
}
mysql = mysql + "order by TState,TEndDate ";//空格被你吃掉了
//象