0
在Visual Studio 2010(使用Visual C#)中,我有一個表單,其中有一個listBox(名爲listBox1)。用戶選擇列表框上顯示的項目之一,然後點擊保存按鈕。該應用程序使用節省了用戶的選擇到數據庫:C#listBox.SelectedIndex來自數據庫
cmd.CommandText = "insert into Table2 (kat) values ('"+listBox1.SelectedIndex.ToString()+"')"
(編輯),例如,它們被保存爲0或1或2等..
然後,我希望應用程序使用即int
在另一個列表框上選擇相同的項目,但在另一個窗體上完全相同的項目。
我至今是:
cmd.CommandText = "select * from Table1 WHERE username='"+textBox1.Text+"'";
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
form1.listBox1.SelectedIndex(dr[0]);
}
}
也同時從數據庫中讀取,你可以使用'int.parse(DR [0]的ToString());'。 – Saravanan
不需要'Int32.Parse'作爲INT插入值而不是STRING –
我不在乎它們是保存爲int還是字符串(已編輯它)。我不知道如何檢索它們 – Shevliaskovic