我使用Add new data source
创建了数据集。然后我创建了BindingSource bs
并使用方法GetData填充了数据(ShoppingMallDataSet是一个新添加的数据集)
void GetData(){
using(ShoppingMallDataSet smds = new ShoppingMallDataSet())
{
using (var conn = new SqlConnection(connection_string))
{
using (var adapter = new ShoppingMallDataSetTableAdapters.TClientTableAdapter() { Connection = conn })
{
adapter.Fill(smds.TClient);
bs.DataSource = smds.TClient;
}
}
}
}
我设置了datagrid数据源rgv.DataSource = bs
的值,然后调用此方法GetData()。在调试器中,bs.DataSource不为null,它有数据。但是gridview没有列,没有数据(但数据源同时不为空)
BindingSource bs = new BindingSource();
.....
rgv.DataSource = bs;
GetData();
....... // rgv doesn't have any data but datasource is not null and has the same value as bs
出现问题或者获取数据的方式不正确吗?
答案 0 :(得分:0)
BindingSource
有两个属性:
除了DataMember
DataSource
bs.DataMember = "TClient";