我目前正試圖從一個SQLite資料庫中添加資料,這就是我所處的位置。組合框中的資料量是正確的,但它沒有顯示實際的資料值,只是顯示 ListViewItem: {},誰能告訴我哪里出了問題。
SQLiteConnection techWorldConnection = new SQLiteConnection(@"Data Source=C。 用戶mwbelOneDriveHomeworkA LevelComp ScienceNEANEA ProgramNEA ExampleinDebugTechWorld. db"); // directs code to location of my database file.
techWorldConnection.Open(); //進入我的資料庫檔案并讀取它。
using (SQLiteConnection conn = new SQLiteConnection(techWorldConnection))
{
SQLiteDataAdapter sda = new SQLiteDataAdapter("Select productName From Products", conn)。)
DataSet dataset = new DataSet() 。
sda.Fill(dataset);
foreach (DataRow row in dataset.Tables[0] .Rows)
{
ListViewItem lvi = new ListViewItem()。
lvi.SubItems.Add(row["productName"].ToString()) 。
OrderProductList.Items.Add(lvi)。
}
}
techWorldConnection.Close()。
uj5u.com熱心網友回復:
組合框中的資料值的數量是正確的,但它沒有顯示實際的資料值,只是顯示ListViewItem: {}
問題在于你是如何添加專案的,特別是這個區域:
。foreach (DataRow row in dataset.Tables[0] .Rows)
{
ListViewItem lvi = new ListViewItem()。
lvi.SubItems.Add(row["productName"].ToString()) 。
OrderProductList.Items.Add(lvi)。
}
你不需要通過回圈集合來獲得你需要的資料,你可以填充一個DataTable,在ComboBox上設定DisplayMember,最后將ComboBox的DataSource設定為你的可資料化。
OrderProductList.DisplayMember = "productName";
SQLiteDataAdapter sda = new SQLiteDataAdapter("Select productName From Products", conn)。
DataTable table = new DataTable()。
sda.Fill(table)。
OrderProductList.DataSource = table;
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/306658.html
標籤:
