Created
September 27, 2019 04:09
-
-
Save sh1ch/d2201319e26a8df524421fdc9258eeb7 to your computer and use it in GitHub Desktop.
(.mdb) 形式のデータベースファイルを識別する例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// <see cref="Access"/> 列挙型は、DB ファイルを作成した Access 種別を表します。 | |
/// </summary> | |
public enum AccessType : int | |
{ | |
/// <summary> | |
/// 未定義 | |
/// </summary> | |
UnDefined = -1, | |
/// <summary> | |
/// 不明 | |
/// </summary> | |
Unknown = 0, | |
/// <summary> | |
/// Access 2.0 | |
/// </summary> | |
Access2 = 2, | |
/// <summary> | |
/// Access 7.0 or (Access 95) | |
/// </summary> | |
Access7_95 = 6, | |
/// <summary> | |
/// Access 97 | |
/// </summary> | |
Access97 = 7, | |
/// <summary> | |
/// Access 2000 | |
/// </summary> | |
Access2000 = 800, | |
/// <summary> | |
/// Access 2002 | |
/// </summary> | |
Access2002 = 802, | |
/// <summary> | |
/// Access 2003 | |
/// </summary> | |
Access2003 = 803, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 参照追加: Microsoft DAO 3.6 Object Library | |
/// <summary> | |
/// データベースファイルを作成した Access の種別を取得します。 | |
/// <para> | |
/// DAO や ADO を利用しコード上で作成したデータベースファイルは識別することができません。 | |
/// </para> | |
/// </summary> | |
/// <returns>Access の種別。</returns> | |
public AccessType GetAccessType() | |
{ | |
var engine = new DAO.DBEngine(); | |
var source = @"DB\Charactors.mdb"; | |
var db = engine.OpenDatabase(source); | |
var props = db.Properties; | |
bool HasProperty(string name) | |
{ | |
foreach (DAO.Property p in props) | |
{ | |
if (p.Name == name) return true; | |
} | |
return false; | |
}; | |
var version = HasProperty("AccessVersion") ? (string)props["AccessVersion"].Value.ToString() : ""; | |
var majorVer = version.Length > 2 ? version.Substring(0, 2) : ""; | |
var projVer = HasProperty("ProjVer") ? (string)props["ProjVer"].Value.ToString() : ""; | |
var type = AccessType.UnDefined; | |
AccessType GetAfterType() | |
{ | |
switch (projVer) | |
{ | |
case "24": return AccessType.Access2002; | |
case "35": return AccessType.Access2003; | |
} | |
return AccessType.UnDefined; | |
}; | |
switch (majorVer) | |
{ | |
case "02": type = AccessType.Access2; break; | |
case "06": type = AccessType.Access7_95; break; | |
case "07": type = AccessType.Access97; break; | |
case "08": | |
type = projVer != "" ? GetAfterType() : AccessType.Access2000; | |
break; | |
case "09": | |
type = projVer != "" ? GetAfterType() : AccessType.Access2002; | |
break; | |
default: | |
break; | |
} | |
return type; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment