C#中我添加了dataGridView控件 设定数据源 控件中有列名显示 却没有数据

2025-03-24 00:52:41
推荐回答(4个)
回答1:

StuDGV.DataBind();是web才会用到的
你换一下制定数据源的容器
StuDGV.DataSource=ds;
试试

如果还不行在
StuDGV.DataSource = ds;
前面加一句清空的
StuDGV.Clear();

回答2:

StuDGV.DataSource = ds.Tables[0].DefaultView;
后面加一行
StuDGV.DataBind();

回答3:

f (stuXH.Text.Trim() != string.Empty)
{
sql = "and XH like '%" + stuXH.Text.Trim() + "%'";
}
if (stuXM.Text.Trim() != string.Empty)
{
sql += "and XM like '%" + stuXM.Text.Trim() + "%'";
}
if (stuZY.Text.Trim() != string.Empty)
{
sql += "and ZY like '%" + stuZY.Text.Trim() + "%'";
}

这个地方的and前面得加个空格
不然就成where 1=1and....
语法错误

回答4:

对,后面加一句绑定语句