asp.net菜鸟 模糊查询问题?
本人刚学C#.好多不懂的地方还请大哥大姐们请教请教! 谢谢~~
下面是本人看教程做的模糊查询(点下去没反应汗死!!)好简单也会出错~~:
首先有个work.cs类有关内容:
public static DataTable selectpersontable()
{
SqlConnection con=work.connection();
con.Open();
SqlDataAdapter sdr=new SqlDataAdapter();
sdr.SelectCommand=new SqlCommand("select * from person",con);
DataSet ds=new DataSet();
sdr.Fill(ds,"person");
return ds.Tables["person"];
(已定义连接数据库, 表名为person)
(CheckBox1 的text值为"按编号查询" pid是一个"textbox控件" 记录的是表person中的"id"列 同时界面还有个DataGrid 控件显示表)
查询按扭代码:
private void Button1_Click(object sender, System.EventArgs e)
{
string c="";
if(this.CheckBox1.Checked)
{
c="id="+this.pid.Text;
}
else
{
c="id like '%'";
}
DataView dv=new DataView(work.selectpersontable());
dv.RowFilter=c;
this.DataGrid1.DataSource=dv;
this.DataGrid1.DataBind();
}