**************:为什么会出现下面的错误?我该怎么解决?
当我不输入条件查找的时候就可以显示数据,当我输入条件的时候就出现下面的错误:
例外詳細資訊: System.Data.OleDb.OleDbException: 關鍵字 'and' 附近的語法不正確。
行 127: myCommand.Fill(ds, "qarpt"); public static string add1(string s,string ss,string s1)
{
string str="" ;
if (s1!=""&&s1!=null)
{
str="and "+s+ss+"'"+s1+"' ";
}
return str;
}
DataView CreateDataSource()
{
string str1,str2;
str2="select * from qarpt where section='"+Session["section"]+"' order by pono desc";
str1="SELECT COUNT(*) as co from qarpt where section='"+Session["section"]+"' order by pono desc";
string s1="",s2="";
s1=Request.Form["radio"];//检验报告主管签核
str1+=add1("radio","=",s1);
str2+=add1("radio","=",s1);
s1=Request.Form["jieguo"];//检验报告判断结果
str1+=add1("jieguo","=",s1);
str2+=add1("jieguo","=",s1);
OleDbConnection myConnection = new OleDbConnection("provider=sqloledb.1;datasource=(local);uid=sa;pwd=123456;initial catalog=othp");
OleDbDataAdapter myCommand = new OleDbDataAdapter(str2, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "qarpt");
MyList.DataSource = ds.Tables["qarpt"].DefaultView;
MyList.DataBind();
return ds.Tables["qarpt"].DefaultView;
myConnection.Close();
Page.DataBind();
}
当我不输入条件查找的时候就可以显示数据,当我输入条件的时候就出现下面的错误:
例外詳細資訊: System.Data.OleDb.OleDbException: 關鍵字 'and' 附近的語法不正確。
行 127: myCommand.Fill(ds, "qarpt"); public static string add1(string s,string ss,string s1)
{
string str="" ;
if (s1!=""&&s1!=null)
{
str="and "+s+ss+"'"+s1+"' ";
}
return str;
}
DataView CreateDataSource()
{
string str1,str2;
str2="select * from qarpt where section='"+Session["section"]+"' order by pono desc";
str1="SELECT COUNT(*) as co from qarpt where section='"+Session["section"]+"' order by pono desc";
string s1="",s2="";
s1=Request.Form["radio"];//检验报告主管签核
str1+=add1("radio","=",s1);
str2+=add1("radio","=",s1);
s1=Request.Form["jieguo"];//检验报告判断结果
str1+=add1("jieguo","=",s1);
str2+=add1("jieguo","=",s1);
OleDbConnection myConnection = new OleDbConnection("provider=sqloledb.1;datasource=(local);uid=sa;pwd=123456;initial catalog=othp");
OleDbDataAdapter myCommand = new OleDbDataAdapter(str2, myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "qarpt");
MyList.DataSource = ds.Tables["qarpt"].DefaultView;
MyList.DataBind();
return ds.Tables["qarpt"].DefaultView;
myConnection.Close();
Page.DataBind();
}
str1="SELECT COUNT(*) as co from qarpt where section='"+Session["section"]+"' "; string s1="",s2="";
s1=Request.Form["radio"];//检验报告主管签核
str1+=add1("radio","=",s1);
str2+=add1("radio","=",s1);
s1=Request.Form["jieguo"];//检验报告判断结果
str1+=add1("jieguo","=",s1);
str2+=add1("jieguo","=",s1);
str1+=" order by pono desc"; str2+=" order by pono desc";