62,046
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
String connectionString = "Data Source=192.168.3.1;Initial Catalog=NorthWind;User Id=sa;Password=撒;";
SqlConnection con = new SqlConnection(connectionString);
con.Open();
String cmd = "Select * From Employees";
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(cmd, con);
DataSet ds = new DataSet();
adapter.Fill(ds, "Employees");
DataTable item = ds.Tables[0];
foreach (DataColumn col in item.Columns)
{
Response.Write("<li>字段名字:" + col.ColumnName + " 类型:" + col.DataType);
}
con.Close();
connectionString = "Provider=sqloledb;Data Source=192.168.3.1;Initial Catalog=NorthWind;User Id=sa;Password=sa";
OleDbConnection cn = new OleDbConnection(connectionString);
cn.Open();
DataTable tables = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
DataTable cols = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns,
new object[] { null, null, "Employees", null });
Response.Write("<h2>Employees 的字段属性:</h2>");
for (int i = 0; i < cols.Columns.Count; i++)
{
Response.Write("<li>" + cols.Columns[i].ColumnName + " = " + cols.Columns[i].DataType);
}
Response.Write("<h2>Employees 的字段名称和类型:</h2>");
foreach (DataRow row in cols.Rows)
{
Response.Write("<li>" + row["COLUMN_NAME"] + " = " + (OleDbType)row["DATA_TYPE"]);
}
con.Close();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
select c.Name as TableName,b.name as ColName,a.name as Type,a.length
from syscolumns a,systypes b,sysobjects
c where c.type= 'U ' and
a.xtype=b.xtype and a.id=c.id