如何从C#中的SQL Server绑定组合框中的列名 [英] how to bind column names in combobox from sql server in c#

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

问题描述


我正在使用3个组合框.
1.在表名称中选择第一个框.
2.显示在其中选择表名称的列名称.
3.选择列名称,然后显示所有数据.
我正在使用while循环为前2个组合框编写代码.所以旧的数据也重复了.然后请给出解决此问题的想法.

Hi,
I am using 3 combo boxes.
1.fist box select in table names.
2.display column names in which select table name.
3.select column name then display the all data.
i am write code for first 2 combo boxes using while loop. so old data also repeated. then please give any idea to solve this problem.

推荐答案


像这样

用于绑定第一个组合,说--dropdownlist1
确保

Do like this

for binding first combo say --dropdownlist1
make sure

autopostback=true 

属性为true

property will be true


dropdownlist1.items.clear();

dropdownlist1.items.clear();

sql="your sql query for filling table names";
//fill data into a data set say ds
<pre>dropdownlist1.datasource=ds;
dropdownlist1.datatextfield= "textfield name";
dropdownlist1.datavaluefield="value field name";
dropdownlist1.databind()


ds.clear();

用于绑定第一个组合,说--dropdownlist2
确保


ds.clear();

for binding first combo say --dropdownlist2
make sure

sql2="your sql query for filling table columname where tablename=" + dropdownlist1.selectedvalue;
<pre lang="cs">//fill data into a data set say ds1

<pre>autopostback=true 

属性将为true

property will be true

dropdownlist2.items.clear();

dropdownlist2.datasource=ds1;
dropdownlist2.datatextfield= "textfield name";
dropdownlist2.datavaluefield="value field name";
dropdownlist2.databind()


ds1.clear();


ds1.clear();

for binding first combo say --dropdownlist2
make sure <pre lang="c#"><pre>autopostback=true </pre></pre>property will be true

sql3="your sql query for filling data of your column where columnname=" + dropdownlist2.selectedvalue;
<pre lang="cs">//fill data into a data set say ds2

dropdownlist3.items.clear();

dropdownlist3.datasource=ds3;
dropdownlist3.datatextfield= &quot;textfield name&quot;;
dropdownlist3.datavaluefield=&quot;value field name&quot;;
dropdownlist3.databind()</pre>


ds3.clear();


可能对您有帮助...


ds3.clear();


may it will help you...


这篇关于如何从C#中的SQL Server绑定组合框中的列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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