|
private void MainForm_Load(object sender, EventArgs e)
{
//Display database information on the interface
try
{
getInformation();//Refresh the form
string select_sql = "select name from address book order by name";
OleDbDataAdapter datadapter = new OleDbDataAdapter(select_sql, con);
DataTable datable = new DataTable();
datadapter.Fill(datable);
comboBox1.DataSource = datable;
comboBox1.DisplayMember = datable.Columns[0].ColumnName;//Control the display of bound values
comboBox1.ValueMember = datable.Columns[0].ColumnName;//Control the display of bound values
}
catch (Exception)
{
MessageBox.Show("Failed to connect to the database!");
}
finally
{
clearTextBox();//Clear the text box information
}
}
Where getInformation() and clearTextBox() are two methods I defined myself |
|