如何获取表中第一列的名称 [英] How to get the name of the first column present in a table

查看:71
本文介绍了如何获取表中第一列的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在asp.net上创建一个Web表单.我在其上放置了2个dropdownlist控件.

1.在第一个下拉列表中,我保存了4个值(Country,State,District,Region),这四个值是存在于sqlserver2008数据库中的表名.
2.我想在第二个下拉列表中显示第一列值(Country_ID或State_ID或District_ID或Region_ID).
在此,第二个下拉列表中的值应填充,具体取决于第一个下拉列表中的所选项目.

问题:-

如果我在第一个下拉列表中选择国家/地区",则国家/地区"表中存在的第一列(Country_ID)值应填充.
如何编写查询语句以在文件后面的C#代码中选择所选表值的第一列.

谢谢
Raj

I am working on asp.net i have created a webform. I placed 2 dropdownlist controls on it.

1. In the first dropdownlist i saved 4 values(Country,State,District,Region) these four are the table names which present in my sqlserver2008 database.

2. I want to display the first column values(Country_ID or State_ID or District_ID or Region_ID) in the 2nd dropdownlist.
Here the value in 2nd dropdownlist should fill depend upon the selected item in 1st dropdownlist.

Question:-

If i select Country in 1st dropdownlist then the first column(Country_ID)values present in the Country table should fill.
How can i write the query statement to select first column of selected table value in my c# code behind file.

Thanks
Raj

推荐答案

这将获得表中的第一列(如果没有列,则为null).

This gets the first column in the table (or null if there are no columns).

DataColumn firstColumn = dataTable.Columns.FirstOrDefault();
string name = "UNKNOWN";
if (firstColumn != null)
{
    name = firstColumn.ColumnName;
}


http://makeadvice.com/blog/?p= 148 [ ^ ]


这篇关于如何获取表中第一列的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆