首先,你这个代码有问题,sql语句like查询的时候要加%符号,虽然不加%语法没有错误,但是查询不到任何结果
然后GetDataSet方法里面不需要绑定,GridView1.DataSource = custDS可以省掉;
最后,祝你成功
GridView1.DataSource = custDS;
删了
改了 你的GetDataSet
DataSet GetDataSet(string name)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=WWW-76912774763;Initial Catalog=sxhj;Integrated Security=True";
SqlCommand selectCMD = new SqlCommand("SELECT Uid,Upower FROM Users where Uid like '%" + name + "%' ", conn);
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = selectCMD;
DataSet custDS = new DataSet();
custDA.Fill(custDS);
return custDS;
}
DataSet GetDataSet(string name)
{
private static strCon= "Data Source=WWW-76912774763;Initial Catalog=sxhj;Integrated Security=True";
SqlConnection conn = new SqlConnection(strCon);
conn.Open();
string sql=string.Format(" SELECT Uid,Upower FROM Users where Uid like '%{0}% '", name);
SqlDataAdapter custDA = new SqlDataAdapter(sql,cn);
DataSet custDS = new DataSet()
custDA.Fill(custDS);
conn.Close();
return custDS;
没找到结果