private void TableView_CurrentCellChanged(object sender, EventArgs e) { if (TableView.CurrentCell != null && TableView.CurrentCell.Value != null) { DataTable ds = (DbType == "Oracle") ? DBconnectionOracle.ShowTable(TableView.CurrentCell.Value.ToString()):DBconnectionSQLServer.ShowTable(DbName, TableView.CurrentCell.Value.ToString()); try { DataView.DataSource = ds;//表从起始行显示在dataGridView里 } catch (Exception) { MessageBox.Show("数据未能正确获得,请重试", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); System.Threading.Thread.CurrentThread.Abort(); //DBView.CurrentCell = DBView.Rows[0].Cells[0]; } } }
private void FormMainOrcl_Load(object sender, EventArgs e) { DataTable dt = (DbType == "Oracle")?DBconnectionOracle.ShowTableList():DBconnectionSQLServer.ShowTableList(DbName); foreach (DataRow row in dt.Rows) { int index = TableView.Rows.Add(); TableView.Rows[index].Cells[0].Value = (DbType == "Oracle") ? row["table_name"].ToString():row["name"].ToString(); } if (TableView.CurrentCell != null && TableView.CurrentCell.Value != null) { DataTable ds = (DbType == "Oracle") ? DBconnectionOracle.ShowTable(TableView.CurrentCell.Value.ToString()) : DBconnectionSQLServer.ShowTable(DbName, TableView.CurrentCell.Value.ToString()); try { DataView.DataSource = ds;//表从起始行显示在dataGridView里 } catch (Exception) { MessageBox.Show("数据未能正确获得,请重试", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); System.Threading.Thread.CurrentThread.Abort(); //DBView.CurrentCell = DBView.Rows[0].Cells[0]; } } }