//前台代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<style type="text/css">
p.a
{
margin-bottom: .0001pt;
text-align: justify;
text-justify: inter-ideograph;
text-indent: 21.0pt;
font-size: 12.0pt;
font-family: "Times New Roman";
margin-left: 0cm;
margin-right: 0cm;
margin-top: 0cm;
}
p.MsoNormal
{
margin-bottom: .0001pt;
text-align: justify;
text-justify: inter-ideograph;
font-size: 12.0pt;
font-family: "Times New Roman";
margin-left: 0cm;
margin-right: 0cm;
margin-top: 0cm;
}
p.MsoNormalIndent
{
margin-bottom: .0001pt;
text-align: justify;
text-justify: inter-ideograph;
text-indent: 21.0pt;
line-height: 15.6pt;
font-size: 12.0pt;
font-family: Arial;
margin-left: 0cm;
margin-right: 0cm;
margin-top: 0cm;
}
.style1
{
border-collapse: collapse;
font-size: 10.0pt;
font-family: "Times New Roman";
margin-left: -33.6pt;
}
</style>
<asp:Repeater runat="server" ID="rpList" OnItemDataBound="rplist_ItemDataBound">
<ItemTemplate>
<p class="a" style="text-indent: 0cm; mso-char-indent-count: 0; mso-outline-level: 2">
<span style="font-family: 宋体"><span lang="EN-US">
<%#Eval("relname")%><o:p></o:p></span></span></p>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" class="style1" style="mso-table-layout-alt: fixed;
mso-padding-alt: 0cm 5.65pt 0cm 5.65pt">
<tr style="mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes; height: 22.5pt">
<td style="width: 45.7pt; text-align: center; border: solid windowtext 1.0pt; border-right: none;
mso-border-top-alt: solid windowtext .75pt; mso-border-left-alt: solid windowtext .75pt;
mso-border-bottom-alt: solid windowtext .75pt; background: #E6E6E6; padding: 0cm 5.65pt 0cm 5.65pt;
height: 22.5pt" width="61">
<p align="center" class="MsoNormal">
<b style="mso-bidi-font-weight: normal"><span style="mso-bidi-font-size: 10.5pt;
font-family: 仿宋_GB2312; mso-ascii-font-family: 宋体">序号</span><span lang="EN-US" style="mso-bidi-font-size: 10.5pt;
font-family: 宋体; mso-fareast-font-family: 仿宋_GB2312; mso-hansi-font-family: "
times new roman""><o:p></o:p></span></b></p>
</td>
<td style="width: 90.6pt; border: solid windowtext 1.0pt; border-right: none; mso-border-top-alt: solid windowtext .75pt;
mso-border-left-alt: solid windowtext .75pt; mso-border-bottom-alt: solid windowtext .75pt;
background: #E6E6E6; padding: 0cm 5.65pt 0cm 5.65pt; height: 22.5pt" width="121">
<p align="center" class="MsoNormal" style="margin-top: 1.0pt; margin-right: 4.0pt;
margin-bottom: 1.0pt; margin-left: 4.0pt; text-align: center; mso-layout-grid-align: none">
<b style="mso-bidi-font-weight: normal"><span style="mso-bidi-font-size: 10.5pt;
font-family: 仿宋_GB2312; mso-ascii-font-family: 宋体">名称</span><span lang="EN-US" style="mso-bidi-font-size: 10.5pt;
font-family: 宋体; mso-fareast-font-family: 仿宋_GB2312; mso-hansi-font-family: "
times new roman""><o:p></o:p></span></b></p>
</td>
<td style="width: 5.0cm; border: solid windowtext 1.0pt; border-right: none; mso-border-top-alt: solid windowtext .75pt;
mso-border-left-alt: solid windowtext .75pt; mso-border-bottom-alt: solid windowtext .75pt;
background: #E6E6E6; padding: 0cm 5.65pt 0cm 5.65pt; height: 22.5pt" width="189">
<p align="center" class="MsoNormal" style="margin-top: 1.0pt; margin-right: 4.0pt;
margin-bottom: 1.0pt; margin-left: 4.0pt; text-align: center; mso-layout-grid-align: none">
<b style="mso-bidi-font-weight: normal"><span style="mso-bidi-font-size: 10.5pt;
font-family: 仿宋_GB2312; mso-ascii-font-family: 宋体">数据类型</span><span lang="EN-US"
style="mso-bidi-font-size: 10.5pt; font-family: 宋体; mso-fareast-font-family: 仿宋_GB2312;
mso-hansi-font-family: " times new roman""><o:p></o:p></span></b></p>
</td>
<td style="width: 169.05pt; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .75pt;
background: #E6E6E6; padding: 0cm 5.65pt 0cm 5.65pt; height: 22.5pt" width="225">
<p align="center" class="MsoNormal" style="margin-top: 1.0pt; margin-right: 4.0pt;
margin-bottom: 1.0pt; margin-left: 4.0pt; text-align: center; mso-layout-grid-align: none">
<b style="mso-bidi-font-weight: normal"><span style="mso-bidi-font-size: 10.5pt;
font-family: 仿宋_GB2312; mso-ascii-font-family: 宋体">注释</span><span lang="EN-US" style="mso-bidi-font-size: 10.5pt;
font-family: 宋体; mso-fareast-font-family: 仿宋_GB2312; mso-hansi-font-family: "
times new roman""><o:p></o:p></span></b></p>
</td>
</tr>
<asp:Repeater runat="server" ID="detail">
<ItemTemplate>
<tr style="mso-yfti-irow: 1; mso-yfti-lastrow: yes; height: 15.8pt">
<td style="width: 45.7pt; border-top: none; border-left: solid windowtext 1.0pt;
border-bottom: solid windowtext 1.0pt; border-right: none; mso-border-top-alt: solid windowtext .75pt;
mso-border-top-alt: solid windowtext .75pt; mso-border-left-alt: solid windowtext .75pt;
mso-border-bottom-alt: solid windowtext .75pt; padding: 0cm 5.65pt 0cm 5.65pt;
height: 15.8pt" width="61">
<p align="center" class="MsoNormalIndent" style="margin-left: 21.0pt; text-align: center;
text-indent: -21.0pt; mso-list: l0 level1 lfo1; tab-stops: list 21.0pt">
<![if !supportLists]> <span style="mso-bidi-font-size: 10.5pt; mso-fareast-font-family: Arial;
mso-bidi-font-family: Arial; mso-ansi-language: #0400; mso-fareast-language: #0400">
<span style="mso-list: Ignore">
<%#Eval("ordinal_position") %><span style="font: 7.0pt " times new roman"">
</span></span></span><![endif]> <span style="mso-bidi-font-size: 10.5pt; mso-ansi-language: #0400;
mso-fareast-language: #0400">
<o:p>
</o:p>
</span>
</p>
</td>
<td style="width: 90.6pt; border-top: none; border-left: solid windowtext 1.0pt;
border-bottom: solid windowtext 1.0pt; border-right: none; mso-border-top-alt: solid windowtext .75pt;
mso-border-top-alt: solid windowtext .75pt; mso-border-left-alt: solid windowtext .75pt;
mso-border-bottom-alt: solid windowtext .75pt; padding: 0cm 5.65pt 0cm 5.65pt;
height: 15.8pt" valign="top" width="121">
<p class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; mso-fareast-font-family: 仿宋_GB2312">
<%#Eval("column_name") %><o:p></o:p></span></p>
</td>
<td style="width: 5.0cm; border-top: none; border-left: solid windowtext 1.0pt; border-bottom: solid windowtext 1.0pt;
border-right: none; mso-border-top-alt: solid windowtext .75pt; mso-border-top-alt: solid windowtext .75pt;
mso-border-left-alt: solid windowtext .75pt; mso-border-bottom-alt: solid windowtext .75pt;
padding: 0cm 5.65pt 0cm 5.65pt; height: 15.8pt" valign="top" width="189">
<p class="MsoNormal">
<span lang="EN-US" style="font-family: 宋体; mso-fareast-font-family: 仿宋_GB2312">
<%#GetT(Eval("data_type"), Eval("character_maximum_length"), Eval("numeric_precision"), Eval("numeric_scale"))%><o:p></o:p></span></p>
</td>
<td style="width: 169.05pt; border: solid windowtext 1.0pt; border-top: none; mso-border-top-alt: solid windowtext .75pt;
mso-border-alt: solid windowtext .75pt; padding: 0cm 5.65pt 0cm 5.65pt; height: 15.8pt"
valign="top" width="225">
<p class="MsoNormal" style="margin-top: 1.0pt; margin-right: 4.0pt; margin-bottom: 1.0pt;
margin-left: 0cm; mso-layout-grid-align: none">
<span style="mso-bidi-font-size: 10.5pt; font-family: 仿宋_GB2312; mso-ascii-font-family: 宋体">
<%#Eval("description")%></span><span lang="EN-US" style="mso-bidi-font-size: 10.5pt;
font-family: 宋体; mso-fareast-font-family: 仿宋_GB2312; mso-hansi-font-family: "
times new roman""><o:p></o:p></span></p>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</div>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
//后台代码
using System;
using System.Collections.Generic;using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Npgsql;
public partial class _Default : System.Web.UI.Page
{
private string str = "";
protected void Page_Load(object sender, EventArgs e)
{
str = Request["conn"];
// if (string.IsNullOrEmpty(str)) return;
RpBind();
}
protected string GetT(object type, object obj1, object obj2, object obj3)
{
string t = type.ToString();
switch (t)
{
case "numeric":
return type + "(" + obj2 + "," + obj3 + ")";
case "character varying":
return type + "(" + obj1 + ")";
}
return t;
}
private void RpBind()
{
string sql = "select relname from pg_stat_user_tables ";
this.rpList.DataSource = getTable(sql);
this.rpList.DataBind();
}
protected void rplist_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("detail") as Repeater;//找到里层的repeater对象
DataRowView rowv = (DataRowView)e.Item.DataItem;
string name = rowv["relname"].ToString();
string sql = @" SELECT
col.ordinal_position,
col.column_name ,
col.data_type ,
col.character_maximum_length,
col.numeric_precision,
col.numeric_scale,
des.description
FROM
information_schema.columns col LEFT JOIN pg_description des
ON col.table_name::regclass = des.objoid
AND col.ordinal_position = des.objsubid
WHERE
table_name = ‘{0}‘
ORDER BY
ordinal_position;";
sql = string.Format(sql, name);
rep.DataSource = getTable(sql);
rep.DataBind();
}
}
private static string conn = "数据库连接字符串";
private DataTable getTable(string sql)
{
NpgsqlConnection connection =new NpgsqlConnection(conn);
NpgsqlDataAdapter dataAdapter = new NpgsqlDataAdapter(sql, connection);
DataSet dataSet =new DataSet();
dataAdapter.Fill(dataSet);
return dataSet.Tables[0];
}
}