asp 数据库查询后如何显示在gridview中

2024-11-23 11:32:55
推荐回答(5个)
回答1:

首先,你这个代码有问题,sql语句like查询的时候要加%符号,虽然不加%语法没有错误,但是查询不到任何结果
然后GetDataSet方法里面不需要绑定,GridView1.DataSource = custDS可以省掉;
最后,祝你成功

回答2:

GridView1.DataSource = custDS;
删了

回答3:

改了 你的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;
}

回答4:

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;

回答5:

没找到结果