public string checkstr(string a,string b)
{
if(a!="")
a=" "+b+"='"+a+"' and";
else
a=" ";
return a;
}
public void find_Click(Object sender,System.EventArgs e)
{
OleDbConnection Con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Server.MapPath("students.mdb"));
string sel;
OleDbDataAdapter Cmd;
sel="select * from stu where"+this.checkstr(getdept,"sdept")+this.checkstr(getscno,"sscno")+this.checkstr(getclno,"sclno")+this.checkstr(getstuname,"sstuname")+this.checkstr(getstusex,"sstusex")+" ;
Cmd=new OleDbDataAdapter(sel,Con);
//if(Cmd.EndsWith("and")==true)
//Cmd=Cmd.Remove(Cmd.Length-3,3);
DataSet ds=new DataSet();
Cmd.Fill(ds,"stu");
DataGrid1.DataSource=ds.Tables["stu"].DefaultView;
DataGrid1.DataBind();
}
这段代码本来是用在连接SQL数据库的,用来判断输入的和数据库的是否一致从而实现查找功能。但是我把它改成了ACCESS的,红色部分由于OleDbConnection不包含 EndsWith、Length、Remove方法而不能使用,只好被我注释掉。但注释掉后又不能正常用。请问我应该怎么修改?
[此贴子已经被作者于2006-11-22 23:10:04编辑过]