首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >核心DataReader.GetSchemaTable()方法抛出NotSupportedException C# .NET标准

核心DataReader.GetSchemaTable()方法抛出NotSupportedException C# .NET标准
EN

Stack Overflow用户
提问于 2018-06-15 05:06:12
回答 1查看 357关注 0票数 0

代码采用C# .NET标准

代码语言:javascript
复制
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许可证。如果您需要更多的上下文,请让我知道。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-06-16 15:51:19

查询select dont have join,只有一个表。

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

代码语言:javascript
复制
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();
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50865937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档