try
{
OleDbDataAdapter da = new OleDbDataAdapter("select * from DT_MeterType", conn);
DataSet ds = new DataSet();
da.Fill(ds);
int _iRowsC = ds.Tables[0].Rows.Count;
string _strIDnum = "";
DataRow dr;
for (int i = 0; i < _iRowsC; i++)//从mdb里读热表类型,主要是为了获取相应的ID号
{
string _strMeterName = ds.Tables[0].Rows[i].ItemArray[2].ToString();
if (String.Compare(_strMeterName, _strMeterModel) == 0)
{
dr = ds.Tables[0].Rows[i]; //获取行索引
_strIDnum = dr[1].ToString();
}
}
conn.Open();
OleDbDataAdapter da1 = new OleDbDataAdapter("select * from DT_lastMeterType", conn);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
if (ds1.Tables[0].Rows.Count == 1) //判断是表否为空
{
string _strUPcmd = "update DT_lastMeterType set";
_strUPcmd += " ID号 = '"+ _strIDnum; //这里就这个update语句,语法错误提醒好几次都没找到,原来就是少了那么一个空格,ID号前加个空格就ok了
_strUPcmd += "',MeterType='" + _strMeterModel;
_strUPcmd += "'where ID号>'1'";
OleDbCommand sqlUpcmd = new OleDbCommand(_strUPcmd, this.conn);
sqlUpcmd.ExecuteNonQuery();
}