现在的位置: 首页 > 综合 > 正文

应用ADO.net得到表

2012年05月16日 ⁄ 综合 ⁄ 共 8409字 ⁄ 字号 评论关闭

'----------------------------------------------------------
'开发者:
'开发时间:2004.9.9
'功能:应用ADO.net得到表
'----------------------------------------------------------
Imports Zy_DataAccess
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class ClsGetTables
 
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:得到所有表
    '----------------------------------------------------------
    Public Function GetAllTables(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                                                           New Object() {Nothing, Nothing, Nothing, Nothing}) ' "TABLE"})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:得系统表
    '----------------------------------------------------------
    Public Function GetSystemTables(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                                                               New Object() {Nothing, Nothing, Nothing, "SYSTEM TABLE"})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:得用户表
    '----------------------------------------------------------
    Public Function GetUserTables(ByVal CnStr As String) As DataTable

        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                                                               New Object() {Nothing, Nothing, Nothing, "TABLE"})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:得到系统视图
    '----------------------------------------------------------
    Public Function GetSystemViews(ByVal CnStr As String) As DataTable

        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                                                               New Object() {Nothing, Nothing, Nothing, "SYSTEM VIEW"}) ' "TABLE"})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:得到用户视图
    '----------------------------------------------------------
    Public Function GetUserViews(ByVal CnStr As String) As DataTable

        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
                                                               New Object() {Nothing, Nothing, Nothing, "VIEW"}) ' "TABLE"})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:得到所有过程
    '----------------------------------------------------------
    Public Function GetStoredProcedures(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Procedures, New Object() {Nothing, Nothing, Nothing, Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:得到数据类型
    '----------------------------------------------------------
    Public Function GetDataTypes(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Provider_Types, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:得到表的列,My_Tablename为空是所有的
    '----------------------------------------------------------
    Public Function GetTableColumns(ByVal CnStr As String, ByVal My_Tablename As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        If My_Tablename.Trim = "" Then
            My_Tablename = Nothing
        End If
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, New Object() {Nothing, Nothing, My_Tablename, Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库名
    '----------------------------------------------------------
    Public Function GetDbname(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Catalogs, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库表列的权限
    '----------------------------------------------------------
    Public Function GetColumn_Privileges(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Column_Privileges, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库表的索引
    '----------------------------------------------------------
    Public Function GetIndexes(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Indexes, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库表的主键
    '----------------------------------------------------------
    Public Function GetPrimary_Keys(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库的存储过程的参数
    '----------------------------------------------------------
    Public Function GetProcedure_Parameters(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Procedure_Parameters, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库的架构信息
    '----------------------------------------------------------
    Public Function GetSchemata(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Schemata, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库的表的记录数统计
    '----------------------------------------------------------
    Public Function GetStatistics(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Statistics, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库的表的记录数统计
    '----------------------------------------------------------
    Public Function GetTable_Statistics(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Table_Statistics, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
    '----------------------------------------------------------
    '开发时间:2004.9.9
    '功能:数据库的中用户可访问的表
    '----------------------------------------------------------
    Public Function GetTables_Info(ByVal CnStr As String) As DataTable
        Dim conn As New OleDbConnection(CnStr)
        conn.Open()
        Dim schemaTable As DataTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables_Info, New Object() {Nothing})
        conn.Close()
        Return schemaTable
    End Function
   
End Class

抱歉!评论已关闭.