错误描述是这样
object reference not set to an instance ofan object代码//创建表
public static void Initialization()
{
_TimeDataCollection = new DataTable();
_TimeDataCollection.Columns.Add(new DataColumn("Code"));
_TimeDataCollection.Columns.Add(new DataColumn("Time"));
_TimeDataCollection.Columns.Add(new DataColumn("Index"));
} private static void SaveToDataTable(object obj)
{
TimeDataStuctue TDS = (TimeDataStuctue)obj;//TimeDataStuctue 是自己定义的类型 DataRow DR; string expression = string.Format("Code = '{0}' and Index ='{1}'", TDS.Code, TDS.Index.ToString());
DataRow[] foundRows = new DataRow[0];
lock (_TimeDataCollection)
{
try
{
// Use the Select method to find all rows matching the filter.
foundRows = _TimeDataCollection.Select(expression); if (foundRows.Length > 0)
{
DR = foundRows[0];
}
else
{
DR = _TimeDataCollection.NewRow();
_TimeDataCollection.Rows.Add(DR);
}
}
catch (Exception e)
{
OnExceptionHappend(e, "SaveToDataTable.FoundRows." + TDS.Code);//传出错误报告
return;
}
}
try
{
DR["Code"] = TDS.Code;//string 类型
DR["Time"] = TDS.Time.ToString("HH:mm:ss");//DateTime 类型
DR["Index"] = TDS.Index.ToString();//int 类型
}
catch (Exception e)
{
OnExceptionHappend(e, "SaveToDataTable.SetRow" + TDS.Code);//传出错误报告,也是发生错误的地方
return;
}
}
object reference not set to an instance ofan object代码//创建表
public static void Initialization()
{
_TimeDataCollection = new DataTable();
_TimeDataCollection.Columns.Add(new DataColumn("Code"));
_TimeDataCollection.Columns.Add(new DataColumn("Time"));
_TimeDataCollection.Columns.Add(new DataColumn("Index"));
} private static void SaveToDataTable(object obj)
{
TimeDataStuctue TDS = (TimeDataStuctue)obj;//TimeDataStuctue 是自己定义的类型 DataRow DR; string expression = string.Format("Code = '{0}' and Index ='{1}'", TDS.Code, TDS.Index.ToString());
DataRow[] foundRows = new DataRow[0];
lock (_TimeDataCollection)
{
try
{
// Use the Select method to find all rows matching the filter.
foundRows = _TimeDataCollection.Select(expression); if (foundRows.Length > 0)
{
DR = foundRows[0];
}
else
{
DR = _TimeDataCollection.NewRow();
_TimeDataCollection.Rows.Add(DR);
}
}
catch (Exception e)
{
OnExceptionHappend(e, "SaveToDataTable.FoundRows." + TDS.Code);//传出错误报告
return;
}
}
try
{
DR["Code"] = TDS.Code;//string 类型
DR["Time"] = TDS.Time.ToString("HH:mm:ss");//DateTime 类型
DR["Index"] = TDS.Index.ToString();//int 类型
}
catch (Exception e)
{
OnExceptionHappend(e, "SaveToDataTable.SetRow" + TDS.Code);//传出错误报告,也是发生错误的地方
return;
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货