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);
}
}