如何从Sql Server数据库表中获取记录到下拉列表 [英] How Do I Fetch Records From Sql Server Database Table To A Drop Down List

查看:128
本文介绍了如何从Sql Server数据库表中获取记录到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL SERVER 2008(sql server authentication)和visual studio 2010.我在数据库表中有一些名为Mst_Status_Common的记录。我想从数据库表中获取特定列到下拉列表。在数据库表中,我有列 - Status_CommonId,Status_CommonName,Active_Status,EntryBy,EntryDate。我想从列Status_CommonName获取数据到下拉列表。该特定列中的数据为:/ CR / E / EN / R / T.



请详细帮助我编写代码。

解决方案

试试....



 string s =从Mst_Status_Common中选择Status_CommonName; 
SqlDataAdapter sda = new SqlDataAdapter(s,connectionName);
DataSet ds = new DataSet();
Sda.Fill(ds);
DropDownListname.DataSource = ds;
DropDownListname.DataBind();





希望我理解你的问题.....


这些示例应该对您有用 -

http://www.java2s.com/Tutorial/ASP.NET/0360__ADO.net-Database/ReaddatafromSQLserverandfillaspdropdownlistC.htm [ ^ ]

http://www.dotnetspark.com/kb/51-data-populate-dropdownlist-through-sql-server。 aspx [ ^ ]

I am working with SQL SERVER 2008(sql server authentication) & visual studio 2010. I have some records in the database table named Mst_Status_Common. I want to get a particular column from the very database table to a drop down list. In the database table I have the columns as - Status_CommonId , Status_CommonName , Active_Status , EntryBy , EntryDate. I want to fetch the data from column Status_CommonName to a drop down list . Data in that particular column are: /CR/E/EN/R/T.

kindly help me with the coding in details.

解决方案

try it....

string s="select Status_CommonName from Mst_Status_Common";
SqlDataAdapter sda=new SqlDataAdapter(s,connectionName);
DataSet ds=new DataSet();
Sda.Fill(ds);
DropDownListname.DataSource=ds;
DropDownListname.DataBind();



hope that i understood ur question.....


These examples should be useful to you -
http://www.java2s.com/Tutorial/ASP.NET/0360__ADO.net-Database/ReaddatafromSQLserverandfillaspdropdownlistC.htm[^]
http://www.dotnetspark.com/kb/51-data-populate-dropdownlist-through-sql-server.aspx[^]


这篇关于如何从Sql Server数据库表中获取记录到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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