如何從主機檔案系統擷取架構集
HostFileConnection
開啟 時,您可以使用 方法來擷取目標資料的 GetSchema
架構資訊。 GetSchema
DataTable
會傳回物件,其中包含目前連接目標之架構資訊的資料列和資料行。
此外,當 開啟時 DBDataReader
,您可以使用 方法來擷取目前結果集 GetSchemaTable
的架構資訊。 GetSchemaTable
DataTable
會傳回物件,其中包含目前結果集的架構資訊的資料列和資料行。 物件 DataTable
會針對結果集的每個資料行包含一個資料列。 架構資料表資料列的每個資料行都會對應至結果集中傳回之資料行的屬性,其中 ColumnName
是 屬性的名稱,而資料行的值則是 屬性的值。
從主機檔案系統擷取架構集
開啟主機檔案系統的連線,並呼叫
HostFileConnection
。呼叫
HostfileConnection.GetSchema
以擷取架構資料。
範例
下列程式碼範例示範如何從連線物件擷取架構集合。 請注意,ETCMLogging 和 HostFileUtils 物件是開發人員建立的物件,可提供記錄和公用程式功能。
public void CNGetSchema(ETCMLogging.Logging logging, string host, string ccsid, string cnstring, HostFileUtils.Utils.HostFileType hostfiletype)
{
HostFileUtils.Oledb oledb = new HostFileUtils.Oledb();
HostFileUtils.Utils u = new HostFileUtils.Utils();
logging.LogInfo(host);
try
{
// Create connection.
HostFileConnection cn = oledb.CreateConnection(logging);
cn.ConnectionString = cnstring;
DataTable dt = cn.GetSchema();
if (dt.HasErrors)
{
logging.LogFail("returned datatable has errors");
}
// Open the connection.
logging.LogInfo("Open Connection");
cn.Open();
DataTable dt2 = cn.GetSchema();
if (dt2.HasErrors)
{
logging.LogFail("returned datatable has errors");
}
int rowcnt = dt.Rows.Count;
for (int i = 0; i < rowcnt; i++)
{
int colcnt = dt.Rows[i].ItemArray.Length;
for (int o = 0; o < colcnt; o++)
{
u.CompareValues(dt.Rows[i][o].ToString(), dt2.Rows[i][o].ToString(), logging);
}
}
// Close the open connection.
cn.Close();
}
catch (Exception e)
{
logging.LogInfo(e.Message);
logging.LogFail(e.StackTrace);
}
}