|
发表于 2020-9-5 14:30:01
|
显示全部楼层
private void MainForm_Load(object sender, EventArgs e)
{
//在界面上显示数据库信息
try
{
getInformation();//刷新窗体
string select_sql = "select name from 通讯录 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;//控制绑定值的显示
comboBox1.ValueMember = datable.Columns[0].ColumnName;//控制绑定值的显示
}
catch (Exception)
{
MessageBox.Show("连接数据库失败!");
}
finally
{
clearTextBox();//清空文本框信息
}
}
其中getInformation()和clearTextBox()是我自己定义的两个方法
|
|