代码使用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,并显示消息&#39;不支持指定方法。&#39;
我安装了IBM.Data.DB2.Core版本1.2.2.100,以及版本11.1许可证。 如果您需要更多上下文,请告诉我。
提前致谢。
答案 0 :(得分:-1)
您查询select没有连接,只有一个表。
我建议你使用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();
}