从没有数据的查询中获取列名

从没有数据的查询中获取列名,第1张

从没数据的查询中获取列名

您要做的第一件事是确保没有数据被返回:

SELECt TOP 0 [vwGetData].* FROM [vwGetData] WHERe 1 = 2;

现在假设您知道如何设置一个DataReader,您将执行以下 *** 作:

using(var reader = command.ExecuteReader()){  // This will return false - we don't care, we just want to make sure the schema table is there.  reader.Read();  var tableSchema = reader.GetSchemaTable();  // Each row in the table schema describes a column  foreach (DataRow row in tableSchema.Rows)  {    Console.WriteLine(row["ColumnName"]);  }}

You can also could also look into the SQL Catalog SYS
Views
.



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5431691.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存