通常需要添加以下引用:
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); } } |