zoukankan      html  css  js  c++  java
  • CUBRID学习笔记 37 ADO.NET Schema Provider

    通常需要添加以下引用:

     
    1
    2
    3
    using System.Data;
    using System.Data.Common;
    using CUBRID.Data.CUBRIDClient;

    定义连接字符串:

     
    1
    2
    /* conection string, please modify before using. */
    string _connString = "server=localhost;database=demodb;port=33000;user=public;password=";

    用 CUBRIDConnectionStringBuilder生成连接字符串 这个我比较喜欢:

     
    1
    2
    3
    4
    5
    6
    7
    8
    string server = "localhost";
    int port = 33000;
    string database = "demodb";
    string user = "public";
    string password = "";
    string encoding = "utf-8";
    CUBRIDConnectionStringBuilder sb = new CUBRIDConnectionStringBuilder(server, port, database, user, password, encoding);
    string _connString = sb.GetConnectionString();

    获取用户表:

     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    /* create a new CUBRIDConnection instance */
    using (CUBRIDConnection conn = new CUBRIDConnection())
    {
        try
        {
            /* set the connection string */
            conn.ConnectionString = _connString;
            /* connect to db server */
            conn.Open();
      
            /* create a new CUBRIDSchemaProvider instance */
            CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
            /* get all tables */
            DataTable dt = schema.GetTables(new string[] { "%" });
      
            /* print all tables */
            for (int i = 0; i < dt.Rows.Count; i++)
                Console.WriteLine(dt.Rowsi2.ToString());
        }
        catch (Exception exp)
        {
            Console.WriteLine(exp.Message);
        }
    }

    获取所有用户:

     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    /* create a new CUBRIDConnection instance */
    using (CUBRIDConnection conn = new CUBRIDConnection())
    {
        try
        {
            /* set the connection string */
            conn.ConnectionString = _connString;
            /* connect to db server */
            conn.Open();
     
            /* create a new CUBRIDSchemaProvider instance */
            CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
            /* get all users */
            DataTable dt = schema.GetUsers(null);
     
            /* print all users */
            for (int i = 0; i < dt.Rows.Count; i++)
                Console.WriteLine(dt.Rowsi0.ToString().ToUpper());
        }
        catch (Exception exp)
        {
            Console.WriteLine(exp.Message);
        }
    }

    获取所有视图: 

     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    /* create a new CUBRIDConnection instance */
    using (CUBRIDConnection conn = new CUBRIDConnection())
    {
        try
        {
            /* set the connection string */
            conn.ConnectionString = _connString;
            /* connect to db server */
            conn.Open();
     
            /* create a new CUBRIDSchemaProvider instance */
            CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
            /* get all tables */
            DataTable dt = schema.GetViews(new string[] { "%" });
     
            /* print all tables */
            for (int i = 0; i < dt.Rows.Count; i++)
                Console.WriteLine(dt.Rowsi2.ToString());
        }
        catch (Exception exp)
        {
            Console.WriteLine(exp.Message);
        }
    }
  • 相关阅读:
    JS知识点简单总结
    Js答辩总结
    JS答辩习题
    轮播
    jQuery选择器总结
    JS的魅力
    JS与JAVA数据类型的区别
    单表查询、多表查询、虚拟表连接查询
    Mysql基本语句
    Mysql数据库
  • 原文地址:https://www.cnblogs.com/wang2650/p/5288011.html
Copyright © 2011-2022 走看看