private void btnGetAllTableName_Click(object sender, EventArgs e) { dbHelper = new DBHelperOracle(txtOracleAddress.Text, txtName.Text, txtPassword.Text); List <string> tableName = GetTableNamesOracle(); this.comBoxAllTableName.DataSource = tableName; }
private void btnDelSelectTable_Click(object sender, EventArgs e) { string tableName = this.comBoxAllTableName.Text.Split('(')[0]; string commandText = "drop table " + tableName; int delTable = DBHelperOracle.ExecuteNonQuery(commandText); // TxtLogHelper.m_CreateErrorLogTxt("1", commandText); dbHelper = new DBHelperOracle(txtOracleAddress.Text, txtName.Text, txtPassword.Text); List <string> allTableName = GetTableNamesOracle(); this.comBoxAllTableName.DataSource = allTableName; }
/// <summary> /// 测试数据库连接 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnTestConnectSQL_Click(object sender, EventArgs e) { try { dbHelper = new DBHelperOracle(txtOracleAddress.Text, txtName.Text, txtPassword.Text); DBHelperOracle.init(); MessageBox.Show("数据库连接成功!", "测试结果", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("连接失败: " + ex.Message, "测试结果", MessageBoxButtons.OK, MessageBoxIcon.Warning); } /* * Try * * 'get the selected connection * Dim strFullConn As String = Me.cboConnections.SelectedItem.ToString * Dim arrayFullConn() As String = strFullConn.Split("|") * Dim strDBType As String = arrayFullConn(0).ToUpper * Dim strDBConnOrig As String = arrayFullConn(1) * Dim strDBConn As String = arrayFullConn(1) * * 'check password * If Not CheckPassword(strDBConn) Then Exit Sub * * 'open the connection based on the connection type * Dim connSQLServer As SqlConnection = Nothing * Dim connOracle As OracleConnection = Nothing * If strDBType = "SQLSERVER" Then * connSQLServer = New SqlConnection(strDBConn) * connSQLServer.Open() * connSQLServer.Close() * ElseIf strDBType = "ORACLE" Then * connOracle = New OracleConnection(strDBConn) * connOracle.Open() * connOracle.Close() * End If * * 'connection worked - store password * If Not m_hashPasswords.Contains(strDBConnOrig) Then * m_hashPasswords.Add(strDBConnOrig, m_strPassword) * End If * * MessageBox.Show("Connection succeeded", "Test Result", MessageBoxButtons.OK, MessageBoxIcon.Information) * * Catch ex As Exception * MessageBox.Show("Connection Failed: " + ex.Message, "Test Result", MessageBoxButtons.OK, MessageBoxIcon.Warning) * End Try*/ }
/// <summary> /// 获取Oracle数据库中所有的表名称 /// </summary> /// <returns></returns> public List <string> GetTableNamesOracle() { List <string> tblist = new List <string>(); try { string selectTables = @" select t.tbname,b.comments from ( select View_Name as tbname from user_views union select Table_Name as tbname from user_tables) t left join USER_TAB_COMMENTS b on b.TABLE_NAME=t.tbname order by t.tbname asc"; /*OleDbDataAdapter da = new OleDbDataAdapter(selectTables, tempmyConn); * DataTable dt = new DataTable(); * da.Fill(dt);*/ DataSet ds = DBHelperOracle.GetDataSet(selectTables); if (ds.Tables.Count > 0) { DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { string tname = dr["tbname"].ToString(); string comment = dr["comments"] == null ? "" : dr["comments"].ToString(); if (string.IsNullOrWhiteSpace(comment)) { tblist.Add(tname); } else { tblist.Add(tname + "(" + comment + ")"); } } } } catch (Exception exp) { // TxtLogHelper.m_CreateErrorLogTxt("0", exp.Message); } finally { } return(tblist); }