txt数据已经读入表1中,在利用表1数据统计最大最小值并记录到表2中时,如果数据量较大,则必须打开数据库,否则会报DBNULL的错误 :对象不能从 DBNull 转换为其他类型
OleDbDataAdapter readHDM = new OleDbDataAdapter("select * from HDM", oledb);
DataSet dmdatas = new DataSet();
readHDM.Fill(dmdatas, "HDM");
OleDbDataAdapter adapterdmh = new OleDbDataAdapter("SELECT * from HDM where 断面号<>''", oledb);
DataSet dmid = new DataSet();
adapterdmh.Fill(dmid, "HDM");
DataRow r = dmid.Tables[0].NewRow();
r["ID"] = dmdatas.Tables[0].Rows.Count + 1;
r["断面号"] = "结束";
dmid.Tables[0].Rows.Add(r);
int rows = dmid.Tables[0].Rows.Count;//统计断面个数
this.dataGridView2.DataSource=dmid.Tables[0];
for (int i = 0; i < rows - 1; i++)
{
ArrayList LC = new ArrayList();//里程
ArrayList GC = new ArrayList();//高程
int starti = (int)dmid.Tables[0].Rows[i][0] - 1;
int endi = (int)dmid.Tables[0].Rows[i + 1][0] - 1;
for (int k = starti + 1; k < endi; k++)//遍历每个断面
{
double LCdata = Convert.ToDouble(dmdatas.Tables[0].Rows[k][2]);
double GCdata = Convert.ToDouble(dmdatas.Tables[0].Rows[k][3]);
LC.Add(LCdata);
GC.Add(GCdata);
}
double LClength = LC.Count;
double GClength = GC.Count;
![img](
######https://img-mid.csdnimg.cn/release/static/image/mid/ask/003771949146174.png "#left")