当前位置: 首页>>代码示例>>C#>>正文


C# OdbcConnection.GetSchema方法代码示例

本文整理汇总了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;
 }
开发者ID:klightspeed,项目名称:ReportCards,代码行数:10,代码来源:ExcelRubrics.cs

示例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();
     }
 }
开发者ID:TMA-AQ,项目名称:AlgoQuest,代码行数:19,代码来源:DataBaseParser.cs

示例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;
                }
            }
        }
开发者ID:superliujian,项目名称:AliasDB,代码行数:41,代码来源:DbHelperODBC.cs

示例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");
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:74,代码来源:OdbcConnectionTest.cs

示例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;
        }
开发者ID:nielsschroyen,项目名称:OdbcImporter,代码行数:17,代码来源:LoadOdbcSource.cs


注:本文中的System.Data.Odbc.OdbcConnection.GetSchema方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。