组合框绑定问题 [英] Combobox binding problem

查看:69
本文介绍了组合框绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在运行时将组合框与名为tblcty的表(具有记录)绑定,但未显示在组合框中.

Hi All,

I am binding combobox at runtime with table named tblcty (which has records) but not showing in combobox.

SqlDataAdapter adp = new SqlDataAdapter("Select * from tblcty", con);
DataSet ds = new DataSet();
adp.Fill(ds);
cbfrom.DataSource = ds.Tables["tblcty"];
cbfrom.DisplayMember= "CtyName";
cbfrom.ValueMember = "CtyID";     



问候!
Aman



Regards!
Aman

推荐答案

在此处查看您的代码.

See your code here.

adp.Fill(ds);
cbfrom.DataSource = ds.Tables["tblcty"];



数据集未根据您要检索的数据库中的表名设置表名本身.

您需要显式定义它,否则,如果您没有定义它,则只需使用索引从数据集中获取表即可.

因此,请使用来更新您的代码段.



dataset is not setting table name itself based on table name in db you''re retrieving.

You need to define it explicitly, In other way if you aren''t defining it then you simply fetch table from dataset using indexing.

So Update your snippet with.

adp.Fill(ds);
cbfrom.DataSource = ds.Tables[0];







OR

adp.Fill(ds,"tblcty");
cbfrom.DataSource = ds.Tables["tblcty"];




希望对您有所帮助.




Hope it helps.


尝试这些.可能有帮助

1.检查ds是否为空.
2.try ds.Tables [0];而不是ds.Tables ["tblcty"];
3.检查DisplayMember名称和Valuemember名称是否与数据集中的列名称相同.
Try these.It may help

1.Check if ds is empty or not.
2.try ds.Tables[0]; instead of ds.Tables["tblcty"];
3.Check DisplayMember name & Valuemember name is the same column name in dataset.


这篇关于组合框绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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