ADO.NET 列名称

发布于 2024-10-04 03:14:33 字数 480 浏览 0 评论 0原文

我正在尝试使用下面的代码获取列名称,但它返回一个奇怪的东西...它返回很多“属性”(包括列名称),我想要的只是结果集中的列名称列表。我做错了什么吗?

reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
DataTable schema = reader.GetSchemaTable();

DataRow myField = schema.Rows[0];
   //For each property of the field...
   foreach (DataColumn myProperty in schema.Columns)
   {
      host.WriteLine("##--> " + myProperty.ColumnName + " = " + myField[myProperty].ToString());
   }

提前感谢大家:)

Miloud B.

I'm trying to get the column names using the code below but it returns a weird stuff... It returns a lot of "properties" (including the column name), all I want is a list of the columns names in the resultset. Am I doing something wrong ?

reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
DataTable schema = reader.GetSchemaTable();

DataRow myField = schema.Rows[0];
   //For each property of the field...
   foreach (DataColumn myProperty in schema.Columns)
   {
      host.WriteLine("##--> " + myProperty.ColumnName + " = " + myField[myProperty].ToString());
   }

Thanks in advance people :)

Miloud B.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很坚强 2024-10-11 03:14:33
reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
DataTable schema = reader.GetSchemaTable();

   //For each property of the field...
   foreach (DataRow row in schema.Rows)
   {
      host.WriteLine("##--> " + row["ColumnName"]);
   }

注意:我在没有 IDE 的情况下编写此代码。请善待。

reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly);
DataTable schema = reader.GetSchemaTable();

   //For each property of the field...
   foreach (DataRow row in schema.Rows)
   {
      host.WriteLine("##--> " + row["ColumnName"]);
   }

Note: I am writing this code without IDE. Please be kind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文