我在那裏後,我將數據插入我的SQL精簡版數據庫combobox1
犯規刷新正確顯示數據的問題。我插入我的資料後,我只需調用下面的方法:插入的數據並沒有顯示正確comboBox1
void fillcomboBox1()
{
if (m_dbConnection != null && m_dbConnection.State == ConnectionState.Closed)
{
m_dbConnection.Open();
}
SQLiteDataAdapter da = new SQLiteDataAdapter("select * from rdpdirectory order by company asc", m_dbConnection);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBox1.Items.Add(dt.Rows[i]["Company"]);
}
m_dbConnection.Close();
}
我插入的代碼如下所示:
void InsertConnectionDetails()
{
if (m_dbConnection != null && m_dbConnection.State == ConnectionState.Closed)
{
m_dbConnection.Open();
}
string sql = @"insert into rdpdirectory (company, server, username, password)
values (@company, @server, @username,@password)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.Parameters.AddWithValue("@company", txtCompany.Text);
command.Parameters.AddWithValue("@server", txtServer.Text);
command.Parameters.AddWithValue("@username", txtUserName.Text);
command.Parameters.AddWithValue("@password", txtPassword.Text);
command.ExecuteNonQuery();
m_dbConnection.Close();
fillcomboBox1();
comboBox1.Refresh();
MessageBox.Show("Done");
}
我認爲這個想法是重新填補數據表和組合框應顯示的值?具體問題是我看到相同值的重複項,但是當我重新啓動應用程序時,正確插入的值顯示。
我該從哪裏補充, ? – PriceCheaperton
@PriceCheaperton:檢查我編輯的答案 –