close

用oledb 查 指定db內所有table

 

    ///


        /// 查詢db內所有table
        /// />
        /// db/>
        ///   StringCollection   />
        protected StringCollection do_qry_tab(string Catalog)
        {
        StringCollection SC = new StringCollection();
        OleDbConnection m_objConn = new OleDbConnection();
        OleDbDataAdapter m_adper = new OleDbDataAdapter();
        String CONNSTR = string.Empty;
        CONNSTR = "Data Source=" + txt_server.Text + ";Initial Catalog=" + Catalog + ";Provider=SQLOLEDB;Persist Security Info=True;User ID=" + txt_id.Text + ";Password=" + txt_pw.Text + "";
        m_objConn.ConnectionString=CONNSTR;
        #region TRY
        try
        {
            m_objConn.Open();
            DataTable dt = new DataTable();
            dt = m_objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] { null, null, null, "TABLE" });  //  若是查view  用"VIEW"
            foreach (DataRow dr in dt.Rows)
            {
                SC.Add(dr["TABLE_NAME"].ToString());
            }

        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            m_objConn.Close();
        }
        #endregion
        return SC;
        }

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 11 的頭像
    11

    冠霖的部落格

    11 發表在 痞客邦 留言(0) 人氣()