• 利用OleDb的GetOLEDBSchemaTable方法得到数据库架构信息.NET教程,数据库应用


    我们能够利用oledb的getoledbschematable方法得到数据库的任何视图,表,存储过程等信息。

    getdatabaseschema.aspx

    <%@ page language="vb" autoeventwireup="false" codebehind="getdatabaseschema.aspx.vb"
    inherits="aspxweb.getdatabaseschema"%>
    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
    <html>
    <head>
    <title>getdatabaseschama</title>
    <meta name="generator" content="microsoft visual studio.net 7.0">
    <meta name="code_language" content="visual basic 7.0">
    <meta name="vs_defaultclientscript" content="javascript">
    <meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
    </head>
    <body ms_positioning="gridlayout">
    <form id="form1" method="post" runat="server">
    <asp:datagrid id="datagrid1" runat="server"></asp:datagrid><br>
    <asp:datagrid id="datagrid2" runat="server"></asp:datagrid><br>
    <asp:datagrid id="datagrid3" runat="server"></asp:datagrid><br>
    <asp:datagrid id="datagrid4" runat="server"></asp:datagrid><br>
    <asp:datagrid id="datagrid5" runat="server"></asp:datagrid><br>
    <asp:datagrid id="datagrid6" runat="server"></asp:datagrid>
    </form>
    </body>
    </html>

    getdatabaseschema.aspx.vb

    imports system
    imports system.data
    imports system.data.oledb

    public class getdatabaseschema
    inherits system.web.ui.page
    protected withevents datagrid2 as system.web.ui.webcontrols.datagrid
    protected withevents datagrid3 as system.web.ui.webcontrols.datagrid
    protected withevents datagrid4 as system.web.ui.webcontrols.datagrid
    protected withevents datagrid5 as system.web.ui.webcontrols.datagrid
    protected withevents datagrid6 as system.web.ui.webcontrols.datagrid
    protected withevents datagrid1 as system.web.ui.webcontrols.datagrid

    #region " web form designer generated code "
    <system.diagnostics.debuggerstepthrough()> private sub initializecomponent()

    end sub

    private sub page_init(byval sender as system.object, byval e as system.eventargs) _
    handles mybase.init
    initializecomponent()
    end sub

    #end region

    private sub page_load(byval sender as system.object, byval e as system.eventargs) _
    handles mybase.load
    如何得到数据库中的架构信息?
    getoledbschematable函数有两个方法:
    oledbschemaguid
    restrictions
    参数oledbschemaguid 的成员:tables, procedures, views, columns, catlogs 等
    参数restrictions为限制条件,是个对象数组,原来过虑架构结果信息,
    每一个对象映射到所返回的datacolumn的值。


    dim strcnn as string
    strcnn = "provider=sqloledb; data source=./netsdk; initial catalog=pubs;user id=sa;password=;"
    dim dataconn as new oledbconnection(strcnn)
    try
    dataconn.open()
    dim schematable as datatable
    schematable = dataconn.getoledbschematable(oledbschemaguid.tables, nothing)
    得到全部的表、视图
    datagrid1.datasource = schematable
    datagrid1.databind()

    schematable = dataconn.getoledbschematable(oledbschemaguid.tables, new object() {nothing, nothing, nothing, "table"})
    得到全部的用户表,用户表类型为table,进行过虑
    datagrid2.datasource = schematable
    datagrid2.databind()

    schematable = dataconn.getoledbschematable(oledbschemaguid.tables, new object() {nothing, nothing, nothing, "view"})
    得到全部的视图
    datagrid3.datasource = schematable
    datagrid3.databind()

    schematable = dataconn.getoledbschematable(oledbschemaguid.procedures, nothing)
    得到全部的存储过程
    datagrid4.datasource = schematable
    datagrid4.databind()

    schematable = dataconn.getoledbschematable(oledbschemaguid.provider_types, nothing)
    得到全部支持的数据类型
    datagrid5.datasource = schematable
    datagrid5.databind()

    schematable = dataconn.getoledbschematable(oledbschemaguid.primary_keys, nothing)
    datagrid6.datasource = schematable
    datagrid6.databind()
    catch ex as exception
    response.write(ex.message.tostring())
    finally
    dataconn.close()
    end try

    end sub

    end class
  • 相关阅读:
    springboot Serving Web Content with Spring MVC
    Java的String中的subString()方法
    required string parameter XXX is not present
    NMON监控linux性能
    Linux下Java性能监控
    Linux常用命令
    Loadrunner测试webservice协议总结
    AWR报告分析
    性能测试指标
    如何保证测试的覆盖率
  • 原文地址:https://www.cnblogs.com/axon/p/13707917.html
Copyright © 2020-2023  润新知