本文介绍了如何从mysql数据库添加项目到组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨大家..我在这里有一个问题,在组合框中添加项目..例如我有一个数据库..我有一个名字,姓氏的样本字段..现在..这里的问题..我不知道如何获得一个例子的姓氏字段..这是我的代码..



  string  query =   select * from customer_tab; 
MySqlCommand cmd;

cmd = new MySqlCommand(query,conn);

MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable table = new DataTable( myTable );
da.Fill(table);

foreach (DataRow row in table.Rows)
{
for int i = 0 ; i < row.ItemArray.Length; i ++)
{
comboBox1.Items.Add(row.ItemArray [ 1 ]的ToString());

}
}
解决方案



hi guys.. im having a problem here on adding items to a combo box.. for example i have a database.. i have which has a sample field of firstname,lastname.. now.. here's the problem.. i dont know how to get just the lastname field for an example.. here's my code..

string query = "select * from customer_tab";
MySqlCommand cmd;

cmd = new MySqlCommand(query, conn);

MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable table = new DataTable("myTable");
da.Fill(table);

foreach (DataRow row in table.Rows)
{
     for (int i = 0; i < row.ItemArray.Length; i++)
     {
          comboBox1.Items.Add(row.ItemArray[1].ToString());

     }
}
解决方案



这篇关于如何从mysql数据库添加项目到组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 07:14