GetSchemaTable() 如何工作?
OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(CommandBehavior.KeyInfo);
DataTable dataTable = oleDbDataReader.GetSchemaTable();
GetSchemaTable()
是如何工作的?
它从 RDBMS 中哪里获取信息?
OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader(CommandBehavior.KeyInfo);
DataTable dataTable = oleDbDataReader.GetSchemaTable();
How does GetSchemaTable()
work?
Where does it get its information in RDBMS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IDataReader.GetSchemaTable()
的实现取决于提供者 - 因此会有所不同。您可以编写自己的提供程序并按照您想要的方式进行操作。老实说,这是框架中的一个糟糕的设计 - 您永远不应该使用返回非类型化
DataTable
或DataSet
的接口方法,因为该结果可能包含任何内容。有点挫败了通过接口来约束它的要点:“你必须有一个返回DataTable
的方法,但我们不关心它有哪些行或列” >即使提供程序是 SQL
GetSchemaTable()
也不会返回到[syscolumns]
或[sysobjects]
。这将是一个额外的数据库调用,需要额外的权限,并且无论如何都不起作用,因为结果集不需要反映数据库中的任何对象。我不确定,但我希望绝大多数
IDataReader.GetSchemaTable()
实现能够读取结果集保存的元数据的某些属性。The implementation of
IDataReader.GetSchemaTable()
is up to the provider - so it will vary. You can write your own providers and do it any way you want.To be honest this is bad bit of design in the framework - you should never have interface methods that return an untyped
DataTable
orDataSet
as that result could contain anything. Kinda defeats the point of constraining it by an interface in the first place: "you must have a method that returnsDataTable
but we don't care what rows or columns it has"Even if the provider is SQL
GetSchemaTable()
doesn't go back to the[syscolumns]
or[sysobjects]
. That would be an additional DB call, require additional privileges and not work anyway, as the result set doesn't need to reflect any objects in the DB.I'm not certain, but I'd expect the vast majority of
IDataReader.GetSchemaTable()
implementations to read some properties of the meta data held with the result set.GetSchemaTable() 读取 ADO.NET 返回的结果集上的元数据。
GetSchemaTable() reads the metadata on the resultset returned by ADO.NET.
来自每个数据库中的系统表(例如,syscolumns、sysobjects 等)。
From the system tables (e.g., syscolumns, sysobjects, etc) in each database.