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);
        }
    }
  • 相关阅读:
    使用 OpenSmtp.dll 发送邮件 (记录) 西安
    国庆假期加班头疼 西安
    asp.net 下 使用 showModalDialog 模式窗口 (记录) 西安
    严重声讨 西安
    牙痛,医生说我这是根尖周炎,有点郁闷
    Google域名被国内某商抢注 竟只得重金去赎
    Windows自带的一个罕为人知的无敌命令
    在CSS中使用继承
    删除字符串最后一个字符的几种方法
    如何在一个RowFilter过的dataview中增加一行
  • 原文地址:https://www.cnblogs.com/wang2650/p/5288011.html
Copyright © 2011-2022 走看看