本文介绍了将数据库数据加载到DataGridView的组合框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将DB数据加载到DataGridView的组合框中.
我尝试了以下代码..
how can i load DB data in to a combobox in a DataGridView.
i tried following code..
private void edit_res_per_Load(object sender, EventArgs e)
{
mycon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\ETMSetms.accdb");
string query = "Select resid as ID, resname as Person_Name, resorg as Organisation, orgadd as Office_Address, resdesg as Designation, resdept as Department,resadd as Residential_Address,resph as Phone_no, reseid as Email_Id From resperson order By resid ";
da = new OleDbDataAdapter(query, mycon);
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
dt = new DataTable();
da.Fill(dt);
dgv1.DataSource = dt;
DataGridViewComboBoxColumn c = new DataGridViewComboBoxColumn();
c.HeaderText = "Designation";
c.DataSource = "resperson";
c.DisplayMember = "resperson.resdesg";
c.ValueMember = "resperson.resdesg";
dgv1.Columns.Insert(4,c);
mycon.Close();
}
但是什么都没用...
谁能帮我...
But nothing is working...
Can any one help me......
推荐答案
c.DataSource = dt;
c.DisplayMember = "Designation";
c.ValueMember = "Designation"
但是,您没有返回指定列表以供选择,因此您所做的工作毫无意义.
Though, you''re not returning a table of Designations to choose from, so what you''re doing is kind of pointless.
c.DataSource = dt;
c.DisplayMember = "Designation";
c.ValueMember = "Designation";
这篇关于将数据库数据加载到DataGridView的组合框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!