0
我在sql中有一個表,它的列是:ID,EmpNo,Name和Usertype。從sql表中檢索數據到dataobrid組合框中
如何檢索Usertpye列中的數據的datagridview組合框
只有用戶類型是一個組合框
在此先感謝。
我在sql中有一個表,它的列是:ID,EmpNo,Name和Usertype。從sql表中檢索數據到dataobrid組合框中
如何檢索Usertpye列中的數據的datagridview組合框
只有用戶類型是一個組合框
在此先感謝。
請嘗試下面的代碼,我希望你想要那樣的東西。
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);
如果您有任何問題或疑問,請隨時問我。
@LeoJb,如果您覺得有用,請將其標記爲答案,這樣也可以幫助其他人 –
這取決於你如何使DGV – Plutonix
你的意思是低於? 1)將Usertype列值綁定到組合框2)將該組合框放在datagridview中。 –
如何將它放在datagridview中? – LeoJb