这个 你是要实现两个模糊查询的方法啊:我给你写个收件人查询的啊 单号与这个基本一样
根据收件人姓名实现模糊查询:
SqlConnection sqlCon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnString"].ToString()); //数据库连接
SqlCommand cmd = null;
string strSql = "";
DataSet ds = null;
public DataSet ListBy(string name)
{
try
{
ds = new DataSet();
strSql = "select * from 表where 名称 like '%" + name + "%'";
if (sqlCon.State != ConnectionState.Open)
sqlCon.Open();
SqlDataAdapter sda = new SqlDataAdapter(strSql, sqlCon);
sda.Fill(ds);
}
catch (Exception e) { }
finally
{
sqlCon.Close();
}
return ds;
}
之后 在你查找按钮的clikc事件中写下
protected void Btn_Insert(object sender, EventArgs e)
{
string name = this.flatName.Text.Trim();
gridview1.datasource=ListBy(name).tables(0);
gridview1.DataBind(); //绑定 gridview
}
好了 希望能帮到你
这是用VISUAL STUDIO 软件中的数据绑定控件做的吧!!你的问题是什么呢?绑定数据源代码如下:
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ToString();
conn.Open();
string strsql = "select * from T_USER where Name='" + name + "'";
SqlCommand com = new SqlCommand(strsql, conn);
SqlDataReader dr = com.ExecuteReader();
这不是典型的Gridview绑定吗