我用VS.NET做页面时遇到这样一个问题,使用“查询”控件,出现这样的提示:
“/cgkoa”应用程序中的服务器错误。
--------------------------------------------------------------------------------在关键字 'and' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 在关键字 'and' 附近有语法错误。源错误:
行 45: System.Data.SqlClient.SqlDataAdapter comm=new SqlDataAdapter(sql,conn);
行 46: System.Data.DataSet ds=new DataSet();
行 47: comm.Fill(ds,"table");
行 48: return ds;
行 49: }
源文件: c:\inetpub\wwwroot\cgkoa\include\db.cs 行: 47
附源码(and语句附近):
string items = "";
string values = "";
string type = "";
string strWhere = "";items = D_Field.SelectedItem.Value;
type = D_Oper.SelectedItem.Value;
values = help.checksingle(T_Value.Text.Trim());if(type == "like")
{
strWhere = " and "+items+" "+type+" '%"+values+"%'";
}
else
{
strWhere = " and "+items+" "+type+" '"+values+"'";
}
“/cgkoa”应用程序中的服务器错误。
--------------------------------------------------------------------------------在关键字 'and' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 在关键字 'and' 附近有语法错误。源错误:
行 45: System.Data.SqlClient.SqlDataAdapter comm=new SqlDataAdapter(sql,conn);
行 46: System.Data.DataSet ds=new DataSet();
行 47: comm.Fill(ds,"table");
行 48: return ds;
行 49: }
源文件: c:\inetpub\wwwroot\cgkoa\include\db.cs 行: 47
附源码(and语句附近):
string items = "";
string values = "";
string type = "";
string strWhere = "";items = D_Field.SelectedItem.Value;
type = D_Oper.SelectedItem.Value;
values = help.checksingle(T_Value.Text.Trim());if(type == "like")
{
strWhere = " and "+items+" "+type+" '%"+values+"%'";
}
else
{
strWhere = " and "+items+" "+type+" '"+values+"'";
}
贴出来看看
偶想也是
private void lan_gan_1_Query_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string items = "";
string values = "";
string type = "";
string strWhere = ""; items = D_Field.SelectedItem.Value;
type = D_Oper.SelectedItem.Value;
values = help.checksingle(T_Value.Text.Trim()); if(type == "like")
{
strWhere = " and "+items+" "+type+" '%"+values+"%'";
}
else
{
strWhere = " and "+items+" "+type+" '"+values+"'";
}
ViewState["sql"] += strWhere; Rebind();
}