2017-01-02 9 views
0

私はsqlのテーブルを持っています。そのカラムは:ID、EmpNo、NameおよびUsertypeです。 DataGridViewのコンボボックスにコンボボックスのsqlテーブルからdatagridviewへデータを取得

をUsertpye列のデータを取得する方法

のみUSERTYPEは、事前に

おかげでコンボボックスです。

+0

DGVをどのように使用しているのかによって異なります – Plutonix

+0

あなたは以下の意味ですか? 1)コンボボックスにUsertype列の値をバインドします。2)そのコンボボックスをdatagridviewの中に置きます。 –

+0

DataGridviewに配置する方法は? – LeoJb

答えて

0

以下のコードを試してみてください。そういうものが欲しいと思います。

using System.Data.SqlServerCe; 

string sqlConnection = "Data Source"; 
SqlCeConnection conn = new SqlCeConnection(sqlConnection); 
conn.Open(); 
//Get bind from database. 
string qryGetCategory = "Query to get data for combo box"; 
SqlCeCommand cmdCat = new SqlCeCommand(qryGetCategory, conn); 
SqlCeDataAdapter daCat = new SqlCeDataAdapter(qryGetCategory, conn); 
DataTable dtCat = new DataTable(); 
daCat.Fill(dtCat); 

//Combobox column. 
DataGridViewComboBoxColumn ComboBoxCol = new DataGridViewComboBoxColumn(); 
ComboBoxCol.DataSource = dtCat; 
ComboBoxCol.Name = "Column name"; 
ComboBoxCol.ValueMember = "Value of member"; 
ComboBoxCol.DisplayMember = "Member to be show"; 
datagridview.Columns.Add(ComboBoxCol); 

ご質問やご質問がございましたら、お気軽にお問い合わせください。

+0

@LeoJbあなたが役に立ったと思ったら、答えとしてマークしてください。 –

関連する問題