Two COMBOBOX interactive code

xiaoxiao2021-03-05  23

Private const string m_strconnection = @ "Jet OLEDB: Global Partial Bulk OPS = 2; Jet OLEDB: registry path =; Jet OLEDB: Database Locking Mode = 1; Jet OLEDB: Database Password =; Data Source =" F: / Source / Study / TestTWOCOMBO / BIN / Debug / Data.mdb ""; password =; jet oledb: Engine Type = 5; Jet OLEDB: Global Bulk Transactions = 1; Provider = "Microsoft.jet. OleDb.4.0" "" "" "Jet OLEDB : System database =; Jet OLEDB: SFP = False; Extended Properties =; Mode = Share Deny None; Jet OLEDB: New Database Password =; Jet OLEDB: Create System Database = False; Jet OLEDB: Do not Copy Locale on Compact = false; Jet OLEDB: Compact Without Replica Repair = false; User ID = Admin; Jet OLEDB: Encrypt Database = false "; private OleDbConnection cn = new OleDbConnection (); private OleDbDataAdapter da; private DataTable dtbDept = new DataTable (); private DataTable dtbEmp = new DataTable (); private void Form1_Load (object sender, System.EventArgs e) {m_ConnectToDB (); da = new OleDbDataAdapter (@ "SELECT * FROM sector", cn); da.Fill (dtbDept); da.SelectCommand .Commandtext = @ "SELECT * FROM staff"; da.fill (DTBEMP M_CloseConnection ();

m_loaddept ();

///

/// Connection Database /// private void m_connecttoDB () {cn.connectionstring = m_strConnection; if (cn.state == connectionState.closed) {cn.open ();}

///

/// Turn the database connection /// private void m_closeConnection () {if (cn.state == connectionState.Open) {cn.close ();}}

///

/// load department information /// private void m_loaddept () {if (dtbdept.rows.count> 0) {cMBDept.dataSource = dtbdept; cMBDept.displaymember = "department name" }}

Private void m_loademp () {if (cMBDept.selectedIndex> = 0) {dtbemp.defaultview.rowfilter = "department ID = '" DTBDEPT.ROWS [CMBDEPT.SELECTEDINDEX] ["Department ID"]. TOSTRING (). TRIM ) " '"; cmbEmp.DataSource = dtbEmp.DefaultView; cmbEmp.DisplayMember = "name";}} private void cmbDept_SelectedIndexChanged (object sender, System.EventArgs e) {m_LoadEmp ();}

转载请注明原文地址:https://www.9cbs.com/read-35719.html

New Post(0)