combobox中的可选项如何能和数据库中我查询出来的表中的一列数据绑定?
解决方案 »
- C#写USB自动识别读写功能
- 请问Top、Right、Left、Bottom哪些是只读的
- 问个比较幼稚的问题啊?不要笑,本人第一次提问。
- 功能:页面表格点击按钮添加、删除行,最后保存所填写的信息,如何实现?
- 誰有導出PDF格式的代碼提供一下.不用系統自帶的那鐘,代碼實現.在線等,可以加分
- 请教:C#中正则表达式
- c#中怎么用程序实现regsvr32的功能?
- 如何解决visual studio.net已检测到指定的web服务器运行的不是ASP.NET1.1版。
- 大家认为该把sqlconncetion连接参数放哪里好了?急
- 问一个有关坐标转换的问题.
- C#里怎样得到系统目录?
- 分享一个技巧:[C#变身大法]把CheckListBox控件转为:RadioListButton[我自己命名了,不要见笑]
/// 添加ComboBox数据
/// </summary>
/// <param name="cb"></param>
/// <param name="tableName"></param>
/// <param name="textFieldName"></param>
/// <param name="valueFieldName"></param>
public static void AddComboBoxData(ComboBox cb,string storeProcedureName,string textFieldName,string valueFieldName,ConditionCollection cc)
{
DataSet ds = new DataSet();
try
{ if (storeProcedureName.ToUpper().IndexOf(" FROM ") > 0)
{
DataAccess.Query(ds,storeProcedureName,CommandType.Text,cc,GlobalObject.GetInstance().Connection);
}
else
{
DataAccess.Query(ds,storeProcedureName,cc,GlobalObject.GetInstance().Connection);
}
if (ds.Tables.Count == 0)
{
throw new ArgumentNullException(storeProcedureName,"No table found after query.");
}
if (ds.Tables[0].Columns.Count == 0)
{
throw new ArgumentException(storeProcedureName,"No column found after query.");
}
if (ds.Tables[0].Columns.IndexOf(textFieldName) < 0)
{
throw new ArgumentException(textFieldName,"can not be found from the columns of datatable after query.");
}
if (ds.Tables[0].Columns.IndexOf(valueFieldName) < 0)
{
throw new ArgumentException(valueFieldName,"can not be found from the columns of datatable after query.");
} cb.DisplayMember = textFieldName;
cb.ValueMember = valueFieldName;
cb.DataSource = ds.Tables[0];
cb.DropDownStyle = ComboBoxStyle.DropDownList; }
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
cb.DataSource = ds.Tables[0];这个是和一个表绑定啊,怎么和一个表中一列绑定呢?
cb.DataSource = ds.Tables[0];这个是和一个表绑定啊,怎么和一个表中一列绑定呢?
-------------------------------------------------------------------------------
查询语句:
ds中的数据从数据库中查询一列就可以。
"select xxx from table"
cb.DataSource = ds.Tables[0];