private void button1_Click(object sender, EventArgs e)
{
string ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=teacher.mdb";//数据库名
OleDbConnection ODConn = new OleDbConnection(ConnStr);
ODConn.Open();
string sel = "select * from t1 ";//t1表名
OleDbCommand ODComm1 = ODConn.CreateCommand();
ODComm1.CommandText = sel;
DataTable MyTable = new DataTable();
OleDbDataAdapter MyAdapter = new OleDbDataAdapter(ODComm1);
MyAdapter.Fill(MyTable);
OleDbConnection ODConn = new OleDbConnection(ConnStr);
ODConn.Open();
string sel = "select * from t1 ";//t1表名
OleDbCommand ODComm1 = ODConn.CreateCommand();
ODComm1.CommandText = sel;
DataTable MyTable = new DataTable();
OleDbDataAdapter MyAdapter = new OleDbDataAdapter(ODComm1);
MyAdapter.Fill(MyTable);
comboBox1.DataSource = MyTable;
comboBox1.DisplayMember = "CompanyName";
comboBox1.ValueMember = "CumtomerID";
ODConn.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//显示combobox控件中当前选择客户的ID和公司名称
string MyInfo = "当前ID是" + comboBox1.SelectedValue as string;
MyInfo += ",companyName是:" + comboBox1.Text;
MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}