我不知道我在這些行中做了什麼錯誤。代碼應該從數據庫獲取數據並將其分配到組合框中。但組合框列表中沒有顯示數據。 我的代碼:如何從數據庫C中獲取數據#
public void employeeListCombo()
{
Employee employeeList = new Employee();
Dataset employees = employeeList.getAllEmployee();
foreach(DataRow dr in employees.Tables[0].Rows){
String selectedEmp = dr["firstName"].ToString();
comboEmployee.DataSource = selectedEmp;
}
}
我有一個問題可能是你感興趣的。請參見[數據庫中的數據集爲空](http://stackoverflow.com/questions/29448761/dataset-from-database-is-empty)。 – mmking 2015-04-06 02:16:42
@mmking,我的sql連接建立在不同的文件中,並允許我不使用這些行SqlDataAdapter adapter = new SqlDataAdapter(); SqlCommand command = new SqlCommand(「SELECT * FROM Orders」); string connString = @「Data Source = localhost \ SQLEXPRESS; Initial Catalog = Northwind; Integrated Security = True」; SqlConnection conn = new SqlConnection(connString);你能指出我在哪裏做錯了嗎? – 2015-04-06 02:44:00
如果comboEmployee是您的組合框,您將爲每個數據行將您的DataSource設置爲不同的字符串。 – mmking 2015-04-06 03:22:12