0

代码采用 C# .NET 标准

var connectionString = $"<connection string here>";
var connection = new DB2Connection(connectionString);
connection.Open();
IDbCommand command = connection.CreateCommand();
string sqlStatement = "<a valid query goes here>";
command.CommandText = sqlStatement;
IDataReader dataReader = command.ExecuteReader();

var data = new DataTable();
data = dataReader.GetSchemaTable(); //This throws a NotSupportedException.
//data.Load(dataReader); //This should work, but the above line is what throws the exception, which is what this method is calling internally.

在未注释掉的最后一行抛出 NotSupportedException,并显示消息“不支持指定的方法”。

我安装了 IBM.Data.DB2.Core 的 1.2.2.100 版本,以及 11.1 版本的许可证。如果您需要更多上下文,请告诉我。

提前致谢。

4

1 回答 1

-1

您查询选择没有连接,只有一个表。

我建议您使用 IDB2 对象的代码:

var connectionString = $"<connection string here>";
string sqlStatement = "<a valid query goes here>";

var connection = new DB2Connection(connectionString);
DB2Command myCommand = new DB2Command(sqlStatement,connection);

connection.Open();

try 
{
  DB2DataReader reader = myCommand.ExecuteReader(CommandBehavior.KeyInfo);

  DataTable dt = reader.GetSchemaTable();

  reader.Close();
}
finally 
{
  connection .Close();
}
于 2018-06-16T07:51:19.227 回答