0

通常,我们通过 C# 连接到 Oracle DB,然后通过 C# 执行查询。但是,我有一个excel表。在该 Excel 表中,在 F 单元格下,我将查询写在一个单元格中。我已将此单元格的值存储为 strParam1。声明如下:

String strParam1 = Convert.ToString(xlRange.Cells[row, 6].Value);

我希望我的程序读取该单元格并执行在该单元格下写入的任何查询,即我希望我的代码读取 strParam1 并执行查询。此处如何使用 excel 表获取和执行查询语句?

发布我的代码

public void UpdateDatabase()
        {
            System.Data.OracleClient.OracleConnection conn = new System.Data.OracleClient.OracleConnection();
            conn.ConnectionString = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.144)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)));UID=mwm;PWD=mwm";
            conn.Open();
            OracleCommand command = conn.CreateCommand();
            command.CommandText = "Select * from \"Task\"";
            command.ExecuteNonQuery();
            command.Dispose();
        }
4

1 回答 1

0

如果我理解了你的问题,这似乎很简单,我想我没有,这就是你想要做的一切

public void UpdateDatabase()
        {
            System.Data.OracleClient.OracleConnection conn = new System.Data.OracleClient.OracleConnection();
            conn.ConnectionString = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.144)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)));UID=mwm;PWD=mwm";
            conn.Open();
            OracleCommand command = conn.CreateCommand();
            command.CommandText = strParam1;
            command.ExecuteNonQuery();
            command.Dispose();
        }
于 2012-07-05T06:19:39.563 回答