
C#出现未将对象引用设置到对象实例程序执行到这句出错 DataGrid.ItemsSource = totalTable.DefaultView; 20
publicstaticDataTableMergeTables(DataTable[]tables,stringhhhDGColName=null){if(tables...
public static DataTable MergeTables(DataTable[] tables, string hhhDGColName = null)
{
if (tables.Length == 0) return null;
DataTable totalTable = new DataTable();
totalTable = tables[0].Clone();
for (int i = 1; i < tables.Length; i++)
{
// if (tables[i] == null || tables[i].Columns.Count == 0) continue;
var obj = new object[tables[i].Columns.Count];
foreach (DataRow row in tables[i].Rows)
{
if (string.IsNullOrEmpty(hhhDGColName) || totalTable.Rows.Find(row[hhhColName]) == null)
{
row.ItemArray.CopyTo(obj, 0);
totalTable.Rows.Add(obj);
}
}
}
return totalTable;
}
List <DataTable> tables = new List<DataTable> ();
if (DK3 != 0 && DK4 != 0 && DK5 != 0 && DK2 == 0)
{
string sql = "select * from T_biao where GZBH = '3'";
DataTable table = CommonUse.SqlHelper.ExecuteDataTable(sql);
tables.Add(table);
}
if (DK3 != 0 && DK4 != 0 && DK5 != 0 && DK1 == 0)
{
string sql = "select * from T_biao where GZBH = '2'";
DataTable table = CommonUse.SqlHelper.ExecuteDataTable(sql);
tables.Add(table);
}
if (DK3 == 0 || DK4 == 0 || DK5 == 0)//变流机输入36V400Hz故障
{
string sql = "select * from T_biao where GZBH = '1'";
DataTable table = CommonUse.SqlHelper.ExecuteDataTable(sql);
tables.Add(table);
}
DataTable totalTable = MergeTables(tables.ToArray());
DataGrid.ItemsSource = totalTable.DefaultView;
}
各位大侠请帮忙急求 展开
{
if (tables.Length == 0) return null;
DataTable totalTable = new DataTable();
totalTable = tables[0].Clone();
for (int i = 1; i < tables.Length; i++)
{
// if (tables[i] == null || tables[i].Columns.Count == 0) continue;
var obj = new object[tables[i].Columns.Count];
foreach (DataRow row in tables[i].Rows)
{
if (string.IsNullOrEmpty(hhhDGColName) || totalTable.Rows.Find(row[hhhColName]) == null)
{
row.ItemArray.CopyTo(obj, 0);
totalTable.Rows.Add(obj);
}
}
}
return totalTable;
}
List <DataTable> tables = new List<DataTable> ();
if (DK3 != 0 && DK4 != 0 && DK5 != 0 && DK2 == 0)
{
string sql = "select * from T_biao where GZBH = '3'";
DataTable table = CommonUse.SqlHelper.ExecuteDataTable(sql);
tables.Add(table);
}
if (DK3 != 0 && DK4 != 0 && DK5 != 0 && DK1 == 0)
{
string sql = "select * from T_biao where GZBH = '2'";
DataTable table = CommonUse.SqlHelper.ExecuteDataTable(sql);
tables.Add(table);
}
if (DK3 == 0 || DK4 == 0 || DK5 == 0)//变流机输入36V400Hz故障
{
string sql = "select * from T_biao where GZBH = '1'";
DataTable table = CommonUse.SqlHelper.ExecuteDataTable(sql);
tables.Add(table);
}
DataTable totalTable = MergeTables(tables.ToArray());
DataGrid.ItemsSource = totalTable.DefaultView;
}
各位大侠请帮忙急求 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询