在组合上添加数据 [英] add data on a combo
本文介绍了在组合上添加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从mysql 5.1的表中选择数据并将这些数据添加到c#的组合框中?
解决方案
尝试:
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM myTable", connection); DataTable dt = new DataTable(); da.Fill(dt); cb.DataSource = dt;
使用ADO.NET与数据库进行交互.
1.从数据表或数据集中的数据库中获取数据
2.使用该数据表/数据库作为Combobox的数据源
3.定义组合框的datatext/datavalue字段.
您应该(可以)选择要显示的字段和要返回值的字段;
例如:
cb.DisplayMember = " ; cb.ValueMember = " ;
>
How can I select data from a table on mysql 5.1 and add these data in a combobox in c#?
解决方案
Try:
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM myTable", connection); DataTable dt = new DataTable(); da.Fill(dt); cb.DataSource = dt;
Use ADO.NET to interact with database.
1. Get data from database in a datatable or a dataset
2. use that datatable/database as a datasource of Combobox
3. define the datatext/datavalue field of combobox.
you should(can) select a field to display and a field to return value;
for example:
cb.DisplayMember="Name"; cb.ValueMember="ID";
这篇关于在组合上添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文