日期:2014-05-19  浏览次数:20414 次

附近有错误
string   strconn   =   "server=localhost;uid=sa;pwd=sa;database=购物 ";
                SqlConnection   cn   =   new   SqlConnection(strconn);
                string   mysql   =   "select   *   from   Product,Price   where   Product.PID=Price.PPID ";
                if   (ddl_pgroup.SelectedIndex.ToString()   !=   "0 ")
                {
                        mysql   =   mysql   +   "and   pgroup= "   +   Convert.ToInt16(ddl_pgroup.SelectedIndex.ToString());
                }
                if   (tbx_pid.Text.ToString()   !=   " ")
                {
                        mysql   =   mysql   +   "and   PID= "   +   Convert.ToInt16(tbx_pid.Text.ToString());
                }
               
                if   (tbx_pname.Text.ToString()!= " ")  
                {
                        mysql   =   mysql   +   "and   pname   like '% "   +   tbx_pname.Text.ToString()   +   "% ' ";
                }
                if   (tbx_pvender.Text.ToString()   !=   " ")
                {
                        mysql   =   mysql   +   "and   pvender   like   '% "   +   tbx_pvender.Text.ToString()   +   "% ' ";
                }
               
                SqlDataAdapter   da   =   new   SqlDataAdapter(mysql,   cn);
                DataSet   ds   =   new   DataSet();
                da.Fill(ds);
                dgd_plist.DataSource   =   ds;
                dgd_plist.DataBind();
                cn.Close();
这是一段搜索的代码,但是每次运行的时候,只要用任何的内容来搜索总是出现错误。比如用pname来搜索,就出现“ 'pname '   附近有语法错误”的问题,哪位高手能指点一下啊,谢谢

------解决方案--------------------
string mysql = "select * from Product,Price where Product.PID=Price.PPID ";
==========================================================================
string mysql = "select * from Product,Price where Product.PID=Price.PPID ";

后面先加一个空格,否则拼接肯定错误

------解决方案-