在组合框中填充数据 [英] Populate data in Combo Box
本文介绍了在组合框中填充数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
任何机构都可以向我发送一条代码,说明如何从sql2005用c#填充combox或列表框.
在此先感谢
Asgar Ali Baig
dear all,
Can any body send me a code how to populate combox or list box in c# from sql2005.
Thanks in advance
Asgar Ali Baig
推荐答案
谢谢您的提问.您可以按照下面的代码.
Thank you for your question. You can follow the bellow code.
public void PopulateGCSCompany(ListBox list, String connectionString)
{
StringBuilder sbQuery = new StringBuilder();
sbQuery.AppendLine(" SELECT ");
sbQuery.AppendLine(" [GCSCompanyId],[CompanyName] ");
sbQuery.AppendLine(" FROM [GCSCompany] ");
sbQuery.AppendLine(" ORDER BY [CompanyName] ASC ");
using (SqlConnection conn = new SqlConnection(connectionString))
{
DataTable companyDataTable = new DataTable();
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sbQuery.ToString(), conn);
sqlDataAdapter.Fill(companyDataTable);
list.DataValueField = "GCSCompanyId";
list.DataTextField = "CompanyName";
list.DataSource = companyDataTable;
list.DataBind();
list.Items.Insert(0, new ListItem("", "0"));
}
}
谢谢,
Mamun
Thanks,
Mamun
与您的代码段一起,而不是仅仅问一个问题?
这是一个简单的问题...为此,您可以使用搜索引擎获得解决方案.
经过努力,随附您的代码段,以便您快速获得解决方案.
在ASP.NET中使用DropDownList和ListBox控件 [发生了类型为"System.ArgumentException"的未处理的异常 [
How about come with your code snippet instead of asking just a question?
It''s a simple question...for this you can get the solution by using search engines.
Here after put your effort & come with your code snippet so that you will get the solutions quickly.
Working with DropDownList and ListBox Controls in ASP.NET[^]
An unhandled exception of type ''System.ArgumentException'' occurred[^]
[/Edit]
这篇关于在组合框中填充数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文