本文整理汇总了C#中System.Data.Odbc.OdbcConnection.GetSchema方法的典型用法代码示例。如果您正苦于以下问题:C# OdbcConnection.GetSchema方法的具体用法?C# OdbcConnection.GetSchema怎么用?C# OdbcConnection.GetSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Odbc.OdbcConnection
的用法示例。
在下文中一共展示了OdbcConnection.GetSchema方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSheets
private List<string> GetSheets(OdbcConnection conn)
{
DataTable tables = conn.GetSchema("Tables");
List<string> sheets = new List<string>();
for (int i = 0; i < tables.Rows.Count; i++)
{
sheets.Add(tables.Rows[i]["TABLE_NAME"].ToString());
}
return sheets;
}
示例2: fill
public void fill(TreeNode node, string odbcConnStr)
{
using (OdbcConnection conn = new OdbcConnection(odbcConnStr))
{
conn.Open();
System.Data.DataTable tableschema = conn.GetSchema(OdbcMetaDataCollectionNames.Tables);
foreach (System.Data.DataRow row in tableschema.Rows)
{
string tn = row["TABLE_NAME"].ToString();
TreeNode trDt = node.Nodes.Add(tn, tn, 2, 2);
foreach (System.Data.DataColumn col in tableschema.Columns)
{
tn = row[col].ToString();
string cn = col.ColumnName;
}
}
conn.Close();
}
}
示例3: GetColumns
public static void GetColumns(string table, ref List<string> fields, ref string primaryKey)
{
//MSSQL:Column_Name Index_Name
//Oracle:ColumnName IndexNname
//TODO:有可能不同的数据库用相同的ODBC获取其Schema返回的Column名字不一样,要注意!!!
using (OdbcConnection connection = new OdbcConnection(connectionString))
{
try
{
connection.Open();
table = Regex.Replace(table, "[\\\"\\[\\]`']", "");
DataTable schemaTable = connection.GetSchema("columns", new string[] { null, null, table, null });
string colName = schemaTable.Columns.Contains("COLUMNNAME") ? "COLUMNNAME" : schemaTable.Columns.Contains("COLUMN_NAME") ? "COLUMN_NAME" : "";
if (colName == "")
return;
foreach (DataRow dr in schemaTable.Rows)
{
fields.Add(dr[colName].ToString());
}
schemaTable = connection.GetSchema("Indexes", new string[] { null, null, table, null });
string indexColName = schemaTable.Columns.Contains("INDEXNAME") ? "INDEXNAME" : schemaTable.Columns.Contains("INDEX_NAME") ? "INDEX_NAME" : "";
if (indexColName == "")
return;
foreach (DataRow dr in schemaTable.Rows)
{
if (dr["INDEX_NAME"].ToString().StartsWith("PK_"))
{
primaryKey = dr[colName].ToString();
break;
}
}
}
catch (OdbcException e)
{
connection.Close();
throw e;
}
}
}
示例4: GetSchema_Connection_Closed
public void GetSchema_Connection_Closed ()
{
OdbcConnection cn = new OdbcConnection ();
try {
cn.GetSchema ();
Assert.Fail ("#A1");
} catch (InvalidOperationException ex) {
// Invalid operation. The connection is closed
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
}
try {
cn.GetSchema ("Tables");
Assert.Fail ("#B1");
} catch (InvalidOperationException ex) {
// Invalid operation. The connection is closed
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
}
try {
cn.GetSchema ((string) null);
Assert.Fail ("#C1");
} catch (InvalidOperationException ex) {
// Invalid operation. The connection is closed
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#C2");
Assert.IsNull (ex.InnerException, "#C3");
Assert.IsNotNull (ex.Message, "#C4");
}
try {
cn.GetSchema ("Tables", new string [] { "master" });
Assert.Fail ("#D1");
} catch (InvalidOperationException ex) {
// Invalid operation. The connection is closed
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#D2");
Assert.IsNull (ex.InnerException, "#D3");
Assert.IsNotNull (ex.Message, "#D4");
}
try {
cn.GetSchema ((string) null, new string [] { "master" });
Assert.Fail ("#E1");
} catch (InvalidOperationException ex) {
// Invalid operation. The connection is closed
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#E2");
Assert.IsNull (ex.InnerException, "#E3");
Assert.IsNotNull (ex.Message, "#E4");
}
try {
cn.GetSchema ("Tables", (string []) null);
Assert.Fail ("#F1");
} catch (InvalidOperationException ex) {
// Invalid operation. The connection is closed
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#F2");
Assert.IsNull (ex.InnerException, "#F3");
Assert.IsNotNull (ex.Message, "#F4");
}
try {
cn.GetSchema ((string) null, (string []) null);
Assert.Fail ("#G1");
} catch (InvalidOperationException ex) {
// Invalid operation. The connection is closed
Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#G2");
Assert.IsNull (ex.InnerException, "#G3");
Assert.IsNotNull (ex.Message, "#G4");
}
}
示例5: GetTableList
private List<string> GetTableList()
{
List<string> tables = new List<string>();
using (OdbcConnection odbcConn = new OdbcConnection(_sourceConnectionString))
{
odbcConn.Open();
DataTable tableschema = odbcConn.GetSchema(OdbcMetaDataCollectionNames.Tables);
foreach (DataRow row in tableschema.Rows)
{
string tableName = row["table_name"].ToString();
tables.Add(tableName);
}
}
return tables;
}