private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode tn = e.Node; TableCols tc = tn.Tag as TableCols; if (tc != null) { AddDataDG(tc); } }
/// <summary> /// 获取列信息 /// </summary> /// <param name="tableName"></param> /// <returns></returns> public List <TableCols> GetTableCols(string tableName) { List <TableCols> list = new List <TableCols>(); try { using (OracleConnection conn = new OracleConnection(connString)) { conn.Open(); OracleCommand cmd = conn.CreateCommand(); string sql = @"select tc.column_name as column_name, tc.data_type as data_type, tc.data_length as data_length, cc.comments as comments from user_tab_columns tc, user_col_comments cc where tc.table_name = cc.table_name and tc.column_name = cc.column_name and tc.table_name = '{0}' order by tc.column_id"; sql = string.Format(sql, tableName); cmd.CommandText = sql; OracleDataReader dr = cmd.ExecuteReader(); TableCols tc = null; while (dr.Read()) { tc = new TableCols(); tc.ColName = dr["column_name"].ToString(); tc.DataType = dr["data_type"].ToString(); tc.DataLength = Convert.ToInt32(dr["data_length"].ToString()); tc.Comments = dr["comments"].ToString(); list.Add(tc); } dr.Close(); } } catch (Exception ex) { this.err = ex.Message; return(null); } return(list); }
/// <summary> /// 增加数据 /// </summary> /// <param name="tc"></param> private void AddDataDG(TableCols tc) { if (IsAdded(tc.ColName)) { return; } DataRow dr = dt.NewRow(); dr["列名"] = tc.ColName; dr["类型"] = tc.DataType; dt.Rows.Add(dr); }