#region 检测是否存在STATE字段,没有就添加 /// <summary> /// 检测是否存在STATE字段,没有就添加 /// </summary> /// <returns></returns> public static bool CheckAndAddColumn() { try { using (OleDbConnection conn = new OleDbConnection(Provider=Microsoft.Jet.OleDb.4.0;Data Source=数据库的完整版路径(.mdb文件);)) { conn.Open(); string strStateSql = "select * from T"; OleDbCommand stateCmd = new OleDbCommand(strStateSql, conn); DataSet dt = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(stateCmd); da.Fill(dt); if (dt.Tables[0].Columns["STATE"] == null) { string addSateSql = "ALTER TABLE T ADD COLUMN STATE Short"; OleDbCommand cmd = new OleDbCommand(addSateSql, conn); if (cmd.ExecuteNonQuery() >= 0) { return true; } else { return false; } } else { return true; } } } catch (Exception ex) { throw ex; } } #endregion