dataset与datatable的问题
DataSet germanyCustomers = customerDataSet.Clone();
DataRow[] copyRows =
customerDataSet.Tables[ "Customers "].Select( "CountryRegion = 'Germany ' ");
DataTable customerTable = germanyCustomers.Tables[ "Customers "];
foreach (DataRow copyRow in copyRows)
customerTable.ImportRow(copyRow);
这段是MSDN上的代码,clone一个dataset,然后从前一个dataset中选取一些行放入新的dataset中
DataSet buystock = historystockDataSet.Clone();
DataRow[] copyRows = historystockDataSet.stock.Select( "type= '买入 ' ");
DataTable buyTable =buystock.Tables.Add( "buy ");
foreach (DataRow copyRow in copyRows)
{
buyTable.ImportRow(copyRow);
}
dataGridView1.DataSource = buystock.Tables[ "buy "];
这个是我自己写的代码,能正常运行,但是datagridview中不显示任何数据。
historystockDataset是一个强类型
------解决方案-------------------- dataGridView1.DataSource = buyTable;
------解决方案--------------------这里dataGridView1.DataSource = buyTable设置一个断点看看,
邦定的数据源,到底有没有数据
historystockDataSet这里面有几个table?
DataSet buystock = historystockDataSet.Clone();
DataRow[] copyRows = historystockDataSet.stock.Select( "type= '买入 ' ");
这句不对。。。
DataTable buyTable =buystock.Tables.Add( "buy "); ????
foreach (DataRow copyRow in copyRows)
{
buyTable.ImportRow(copyRow);
}
dataGridView1.DataSource = buystock.Tables[ "buy "];
------解决方案--------------------dataGrid.DataSource = buyTable