【问题标题】:ADO.Net - How to insert data in table without knowing the schemaADO.Net - 如何在不知道架构的情况下在表中插入数据
【发布时间】:2014-02-04 17:32:36
【问题描述】:

我有一个场景,我需要使用 ADO.Net 的数据表和适配器将一些数据插入到 oracle 表中。表的模式是未知的。我该怎么做?

【问题讨论】:

    标签: ado.net


    【解决方案1】:

    你看过这里吗 - Retrieving Database Schema Information? 您可以使用 GetSchema 方法帮助您以编程方式检查数据库的架构。该方法返回模式信息的DataTable。 (尽管 OracleClient 现在在技术上已被弃用)。

    string myConnection = @<fill in your connectionstring here>
    
    using (OracleConnection connection = new OracleConnection(myConnection))
    {
       connection.Open();
    
       DataTable schemaTable = connection.GetSchema("Tables");
    
       foreach(DataRow row in schemaTable.Rows)
          Console.WriteLine(row["TABLE_NAME"];
    } // end using OracleConnection
    

    将为您获取 ConnectionString 指向的数据库中的所有可用表。如果您阅读有关链接的信息,您会发现您可以使用这个非常有用的方法进入整个数据库。 希望这能助您一臂之力!

    【讨论】:

      猜你喜欢
      • 2016-06-17
      • 2021-03-25
      • 2011-07-29
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 2020-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多