1 protected void Button1_Click(object sender, EventArgs e)
2 {
3 //得到目前内网可用的SqlServer
4 System.Data.Sql.SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
5 DataTable dt1 = instance.GetDataSources();
6 Response.Write("目前内网可用的SqlServer" + "<br/>");
7 foreach (DataRow dr in dt1.Rows)
8 {
9 Response.Write(dr[0].ToString() + "<br/>");
10 }
11 Response.Write("==========================");
12 //得到某数据库 的 架构集合
13 string strConn = "Data Source=192.168.0.36;Initial Catalog=NorthWind;Persist Security Info=True;User ID=sa;Password=sa";
14 System.Data.SqlClient.SqlConnection conn = new SqlConnection(strConn);
15 conn.Open();
16 DataTable dt2 = conn.GetSchema();
17 Response.Write("数据库 的 架构集合"+"<br/>");
18 Response.Write("<table border='1'>");
19 foreach (System.Data.DataRow row in dt2.Rows)
20 {
21 Response.Write("<tr>");
22 foreach (System.Data.DataColumn col in dt2.Columns)
23 {
24 Response.Write("<td>"+col.ColumnName + "</td><td>" + row[col]+"</td>");
25 }
26 Response.Write("<tr/>");
27 }
28 Response.Write("</table>");
29
30 //具体应用 得到某数据库下的用户表名
31 //string strConn = "Data Source=192.168.0.36;Initial Catalog=NorthWind;Persist Security Info=True;User ID=sa;Password=sa";
32 //System.Data.SqlClient.SqlConnection conn = new SqlConnection(strConn);
33 //conn.Open();
34 string[] strArray = new string[4];
35 strArray[3] = "BASE TABLE";// VIEW
36 DataTable dt3 = conn.GetSchema("Tables", strArray);
37 Response.Write("==========================");
38 Response.Write("某数据库下的用户表名");
39 foreach (DataRow dr in dt3.Rows)
40 {
41 Response.Write(dr["TABLE_NAME"].ToString());
42 Response.Write("<br/>");
43 }
44
45 }
http://www.cnblogs.com/freeliver54/archive/2006/12/13/590506.html