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); } } |
作者:过错
出处:http://www.cnblogs.com/wang2650/
关于作者:net开发做的久而已。十余年时光虚度!
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题,可以邮件:wang2650@163.com
联系我,非常感谢。