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' 附近有语法错误”的问题,哪位高手能指点一下啊,谢谢
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' 附近有语法错误”的问题,哪位高手能指点一下啊,谢谢
解决方案 »
- 请教高手!!!asp.net后台接收jquery传数组值
- 多级联动,一环套一环,即使使用AJAX,还是要局部回发,有其他什么好办法
- 怎么给button添加mouseover style 我是这么写的
- DataList的距离小问题 在线等呢
- select(sql)带参数的方法
- 一个关于存储过程的问题
- 请问用CAPICOM控件签名时,hash算法是在哪里决定的?
- 关于DataGrid排序的问题
- 请教一个SQL的问题!感谢!!!!
- 请问如何实现将服务器上的ACCESS库中的一个或多个表另存到本地的ACCESS新库中?
- “system.web.ui.webcontrols.dropdownlist并不包含对selectedvalue的定义”是怎么回事?
- <authentication mode="Forms" >里Cookie名称怎么找?
==========================================================================
string mysql = "select * from Product,Price where Product.PID=Price.PPID ";后面先加一个空格,否则拼接肯定错误
mysql = mysql + "and PID=" + Convert.ToInt16(tbx_pid.Text.ToString());
mysql = mysql + "and pname like'%" + tbx_pname.Text.ToString() + "%'";
mysql = mysql + "and pvender like '%" + tbx_pvender.Text.ToString() + "%'";这四条语句在and前面都加个空格
======================================================================like和'之间加个空格错误估计就这么多了吧,不过还有地方写的不是很好...
SqlConnection cn = new SqlConnection(strconn);
string mysql = "select * from Product,Price where Product.PID=Price.PPID";
if (ddl_pgroup.SelectedIndex.ToString() != "0")
{
mysql += " and pgroup=" + Convert.ToInt16(ddl_pgroup.SelectedIndex.ToString());
}
if (tbx_pid.Text.ToString() != "")
{
mysql += " and PID=" + Convert.ToInt16(tbx_pid.Text.ToString());
}
if (tbx_pname.Text.ToString()!="")
{
mysql += " and pname like '%" + tbx_pname.Text.ToString() + "%'";
}
if (tbx_pvender.Text.ToString() != "")
{
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();