首页 »DotNet » 数据库代码:C#分析数据库结构 使用XSL模板自动生成代码 »正文
数据库代码:C#分析数据库结构 使用XSL模板自动生成代码
来源: 发布时间:星期五, 2009年1月9日 浏览:141次 评论:0
<html> <head> <TITLE>分析数据库结构,自动生成代码</TITLE> <meta http-equiv="Content-Type" content="text/html; char =gb2312"> </head> <frame cols="237,767" rows="*"> <frame src="dbxml.aspx"> <frame name="code" src="about:blank"> </frame > </html> ########################### dbxml.aspx 文件内容 ![](/icons/31078dou.gif) 该文件没有C#代码文件 ############# <script language="C#" runat ="server">
.Xml.XmlDocument myCfgXML = .Xml.XmlDocument ; // 获得系统配置 串
GetAppConfig( strKey) {
.Xml.XmlElement cfgElement = myCfgXML.SelectSingleNode ("// ting[@key='" + strKey + "']" ) as .Xml.XmlElement ;
( cfgElement null )
"";
![](/icons/31078else.gif)
cfgElement.InnerText ; } // 判断 串是否是空白 串 bool isBlankString( strText ) {
(strText != null) {
iCount; for(iCount=0;iCount<strText.Length ;iCount ) {
( .Char.IsWhiteSpace ( strText[iCount]) false)
false; } }
true; } void Page_Load(Object sender, EventArgs e) { // 加载系统配置文件 myCfgXML.Load(this.MapPath(".") + "dbxmlcfg.xml");
strType = this.Request["type"];
strXSL = " .xml";
(strType null) strType = "querytable";
.Xml.XmlDocument myDoc = .Xml.XmlDocument ; myDoc.LoadXml("<dbxml />");
strConnection = GetAppConfig("conndbxml");
.Text.Encoding myEncode = .Text.Encoding.GetEncoding(936);
(isBlankString(strConnection) false) { using( .Data.OleDb.OleDbConnection myConn = .Data.OleDb.OleDbConnection(strConnection)) { myConn.Open ;
(myConn.State .Data.ConnectionState.Open ) {
strSQL = GetAppConfig(strType + "_" + myConn.Provider);
(isBlankString(strSQL) false) { using( .Data.OleDb.OleDbCommand myCmd = myConn.CreateCommand ) {
strTableName = null;
(strType.Equals("queryfield")) { // 修正SQL语句
strTableList = this.Request.Form["tablelist"];
strTables = strTableList.Split(",".ToCharArray ); strXSL = .Web.HttpUtility.UrlPathEncode(this.Request.Form["template"] ) + ".xml"; strTableList = null; for( iCount = 0 ; iCount < strTables.Length ; iCount ) {
(isBlankString(strTables[iCount]) false) {
(strTableList null) strTableList = "'" + strTables[iCount] + "'";
![](/icons/31078else.gif) strTableList = strTableList + ",'" + strTables[iCount] + "'"; } } strSQL = strSQL.Replace("#tablelist", strTableList); myCmd.CommandText = strSQL ;
strLastTableName = null;
strFieldName = null;
.Xml.XmlElement TableElement = null;
.Data.OleDb.OleDbDataReader myReader = myCmd.ExecuteReader ; while(myReader.Read ) { strTableName = myReader[0].![](/icons/31078ToString.gif) .ToUpper ;
(strTableName.Equals(strLastTableName) false) { // 填充表介绍说明元素 strLastTableName = strTableName ; TableElement = myDoc.CreateElement("table"); TableElement.SetAttribute("tablename", strTableName); myDoc.DocumentElement.AppendChild(TableElement); } // 填充字段介绍说明元素
.Xml.XmlElement FieldElement = myDoc.CreateElement("field"); FieldElement.SetAttribute("fieldname", myReader[1].![](/icons/31078ToString.gif) ); FieldElement.SetAttribute("fieldtype", myReader[2].![](/icons/31078ToString.gif) ); FieldElement.SetAttribute("fieldwidth", myReader[3].![](/icons/31078ToString.gif) ); FieldElement.SetAttribute("is ", (myReader[2].![](/icons/31078ToString.gif) .ToUpper .IndexOf("CHAR")>=0?"1":"0")); strFieldName = myReader[1].![](/icons/31078ToString.gif) ;
iLen = myEncode.GetByteCount(strFieldName);
(iLen < 20) FieldElement.SetAttribute("fixname", strFieldName + (' ', 20 - iLen)); TableElement.AppendChild(FieldElement); } myReader.Close ; }
![](/icons/31078else.gif) { // 填充模板列表
strFileNames = .IO.Directory.GetFiles(this.Server.MapPath("."),"temp_*.xml"); for( iCount = 0 ; iCount < strFileNames.Length ; iCount ) {
.Xml.XmlElement tempXML = myDoc.CreateElement("template"); tempXML.SetAttribute("key", .IO.Path.GetFileNameWithoutExtension(strFileNames[iCount])); myDoc.DocumentElement.AppendChild(tempXML); } // 填充表名列表 myCmd.CommandText = strSQL ;
.Data.OleDb.OleDbDataReader myReader = myCmd.ExecuteReader ;
.Xml.XmlElement TableElement = null; while(myReader.Read ) { TableElement = myDoc.CreateElement("table"); myDoc.DocumentElement.AppendChild(TableElement); strTableName = myReader[0].![](/icons/31078ToString.gif) ; TableElement.SetAttribute("name", strTableName ); TableElement.SetAttribute("count", myReader[1].![](/icons/31078ToString.gif) );
iLen = myEncode.GetByteCount(strTableName);
(iLen < 20 ) TableElement.SetAttribute("fixname",strTableName + (' ', 20 - iLen)); } myReader.Close ; } } } } myConn.Close ; } } // 输出文档 this.Response.ContentType = "text/xml"; this.Response.ContentEncoding = myEncode ; this.Response.Write("<?xml version="1.0" encoding="GB2312" ?>"); this.Response.Write("<?xml-stylesheet type="text/xsl" href="" + strXSL + ""?>"); this.Response.Write(myDoc.DocumentElement.OuterXml); } </script>
文件 dbxmlcfg.xml内容 -------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8" ?> <application> < tings> < ting key="conn">Provider=SQLOLEDB.1;Password=123456;Persist Security Info=True;User ID=CPR;Initial Catalog=HTIOA;Data Source=192.168.0.124</ ting> < ting key="conndbxml">Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=IssueVision;Data Source=(local)</ ting> <!-- 定义查询表结构使用 ![](/icons/31078de.gif) SQL语句 queryfield_驱动 ![](/icons/31078chengxu.gif) 名称 定义了查询指定表 ![](/icons/31078de.gif) 字段定义 ![](/icons/31078de.gif) SQL语句 ![](/icons/31078dou.gif) 该语句带有 ![](/icons/31078yi.gif) 个参数 querytable_驱动 ![](/icons/31078chengxu.gif) 名称 定义了查询所有表名及其字段个数 ![](/icons/31078de.gif) SQL语句 ![](/icons/31078dou.gif) 该语句没有参数 目前定义了 oracle和ms sql server ![](/icons/31078de.gif) SQL语句 --> < ting key="queryfield_OraOLEDB.Oracle.1">Select TName ,CName ,coltype ,width From Col where tname in (#tablelist) Order by TName,CName</ ting> < ting key="querytable_OraOLEDB.Oracle.1">Select TName ,count(*) From Col group by tname Order by TName </ ting> < ting key="queryfield_SQLOLEDB.1"><![CDATA[select sysobjects.name ,syscolumns.name ,systypes.name ,syscolumns.length from syscolumns,sysobjects,systypes where syscolumns.id=sysobjects.id and syscolumns.xtype=systypes.xtype and sysobjects.type='U' and systypes.name <>'_default_' and systypes.name<>'sysname' and sysobjects.name in (#tablelist) order by sysobjects.name,syscolumns.name]]></ ting> < ting key="querytable_SQLOLEDB.1"><![CDATA[select sysobjects.name ,count(*) from syscolumns,sysobjects,systypes where syscolumns.id=sysobjects.id and syscolumns.xtype=systypes.xtype and sysobjects.type='U' and systypes.name <>'_default_' and systypes.name<>'sysname' group by sysobjects.name order by sysobjects.name]]></ ting> </ tings> </application>
####################### ![](/icons/31078main.gif) .xml ################################## <?xml version="1.0" encoding="gb2312" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/*"> <html> <head> <title></title> <style> select2{ font-family: "宋体"; font-size: 12px} body{ font-family: "宋体"; font-size: 12px} table{ width:100%; border-collapse:collapse; border: 1px #CC0066 solid; font-family: "宋体"; font-size: 12px} .tablehead{background-color:#CCCCFF} td{ border: 1px #CC0066 solid} </style> </head> <body leftmargin='1' rightmargin='1' topmargin="1"> <form name="frm" target="code" method="POST" action="dbxml.aspx?type=queryfield"> 模板<select name="template"> <xsl:for-each select="template"> <option> <xsl:attribute name="value"> <xsl:value-of select="@key" /> </xsl:attribute> <xsl:value-of select="@key" /> </option> </xsl:for-each> </select> <input type="submit" value="提交" /> <table> <tr ="tablehead"> <td nowrap="1">选择</td> <td nowrap="1">表名</td> <td nowrap="1">字段个数</td> </tr> <xsl:for-each select="table"> <tr> <td nowrap="1"> <input type="checkbox" name="tablelist" style="width:13;height:13"> <xsl:attribute name="value"> <xsl:value-of select="@name" /> </xsl:attribute> </input> </td> <td> <xsl:value-of select="@name" /> </td> <td> <xsl:value-of select="@count" /> </td> </tr> </xsl:for-each> </table> </form> </body> </html> </xsl:template> </xsl:stylesheet>
############################### temp_CSharp.xml 内容 ############################################ <?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <html> <head></head> <body> <xsl:for-each select="*/table"> <br />-------------- 文件名 <xsl:value-of select="@tablename" />.cs ----------------------------- <pre style=" background-color:gainsboro"> //----------------------------------------------------------------------------- <xsl:text disable-output-escaping="yes"> /// <summary></xsl:text> /// 数据库表 <xsl:value-of select="@tablename" /> 操作对象 /// 编制: 代码生成器 /// 时间: <xsl:text disable-output-escaping="yes"> /// </summary></xsl:text> public Struct<xsl:value-of select="@tablename" /> : CommonStruct { private const c_TableName ="<xsl:value-of select="@tablename" />"; // 定义数据库字段变量 //////////////////////////////////////////////////////////////// <xsl:for-each select="*"> <xsl:variable name="csharptype"> <xsl:choose> <xsl:when test="@is ='1'"> </xsl:when> <xsl:when test="boolean('true')"> </xsl:when> </xsl:choose> </xsl:variable> <xsl:variable name="lowfieldname"> <xsl:value-of select="translate(@fieldname,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" /> </xsl:variable> private <xsl:value-of select="$csharptype" /> m_<xsl:value-of select="@fixname" /> ; // 字段 <xsl:value-of select="@cname" /> </xsl:for-each> // 定义属性 /////////////////////////////////////////////////////////// <xsl:for-each select="*"> <xsl:variable name="csharptype"> <xsl:choose> <xsl:when test="@is ='1'"> </xsl:when> <xsl:when test="boolean('true')"> </xsl:when> </xsl:choose> </xsl:variable> /// <xsl:text disable-output-escaping="yes"><summary></xsl:text> /// 设置/返回数据库字段属性 <xsl:value-of select="@cname" /> /// <xsl:text disable-output-escaping="yes"></summary></xsl:text> /// <xsl:text disable-output-escaping="yes">< s></xsl:text><xsl:value-of select="@cname" /><xsl:text disable-output-escaping="yes"> </ s></xsl:text> public <xsl:value-of select="$csharptype" /> m<xsl:value-of select="@fieldname" /> { get{ m_<xsl:value-of select="@fieldname" /> ;}
{ m_<xsl:value-of select="@fieldname" /> = value ;} } </xsl:for-each>
public getTableName![](/icons/31078kh.gif) { c_TableName ;}
public getSelectSQL![](/icons/31078kh.gif) {
"Select <xsl:for-each select="*"> <xsl:value-of select="normalize-space(@fieldname)" /> <xsl: test="position != last ">,</xsl: > </xsl:for-each> From " + c_TableName ; }
public getTypeName![](/icons/31078kh.gif) {
"<xsl:value-of select="translate(@tablename,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" />"; }
public SearchKey( strKey) {
getSelectSQL + " Where SEQ =" + strKey ; } public override bool SetCommandParams( .Data.OleDb.OleDbCommand myCmd,bool SetValues ) {
(myCmd!= null) { myCmd.Parameters.Clear ; <xsl:for-each select="*"> myCmd.Parameters.Add("<xsl:value-of select="normalize-space(@fieldname)" />", .Data.OleDb.OleDbType.<xsl: test="@is ='1'">VarWChar</xsl: ><xsl: test="@is ='0'">Integer</xsl: >);</xsl:for-each>
(SetValues) { <xsl:for-each select="*"> myCmd.Parameters[<xsl:value-of select="position -1" />].Value = m_<xsl:value-of select="@fieldname" /> ; // 字段 <xsl:value-of select="@cname" /> </xsl:for-each> }
true; }
false; } public override bool SetInsertCommand( .Data.OleDb.OleDbCommand myCmd) {
(myCmd != null) { myCmd.CommandText ="Insert Into " + c_TableName + " ( <xsl:for-each select="*">[<xsl:value-of select="normalize-space(@fieldname)" />]<xsl: test="position != last ">,</xsl: > </xsl:for-each>) Values (<xsl:for-each select="*">?<xsl: test="position != last ">,</xsl: > </xsl:for-each>)";
this.SetCommandParams(myCmd,true); }
false; } public override bool SetUpdateCommand( .Data.OleDb.OleDbCommand myCmd) {
(myCmd != null) { myCmd.CommandText ="Update " + c_TableName + " Set <xsl:for-each select="*">[<xsl:value-of select="normalize-space(@fieldname)" />]=? <xsl: test="position != last ">,</xsl: ></xsl:for-each> Where SEQ=" + m_SEQ ;
this.SetCommandParams(myCmd,true); }
false; } public override bool SelectRS( .Data.OleDb.OleDbDataReader myReader) { try {
(myReader != null) {
(myReader.FieldCount 5) { <xsl:for-each select="*"> m_<xsl:value-of select="@fixname" /> = Convert.To<xsl: test="@is ='1'">String</xsl: ><xsl: test="@is ='0'">Int32</xsl: >(myReader[<xsl:value-of select="position -1" />]);</xsl:for-each>
true; } } } catch {}
false; } public override bool ToXML( .Xml.XmlElement myElement) {
(myElement != null) { <xsl:for-each select="*"> myElement.SetAttribute("<xsl:value-of select="translate(@fieldname,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" />",m_<xsl:value-of select="@fieldname" /><xsl: test="@is ='0'">.![](/icons/31078ToString.gif) </xsl: >);</xsl:for-each>
true; }
false; } public override bool FromXML( .Xml.XmlElement myElement) { try {
(myElement != null) { <xsl:for-each select="*"> m_<xsl:value-of select="@fixname" /> = <xsl: test="@is ='0'">Convert.ToInt32(</xsl: >myElement.GetAttribute("<xsl:value-of select="translate(@fieldname,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" />")<xsl: test="@is ='0'">)</xsl: >;</xsl:for-each>
true; } } catch {}
false; } }// 数据库操作类 Struct<xsl:value-of select="@tablename" /> 定义结束 </pre> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
########################## temp_HTML代码.xml ##################################################### <?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/*"> <html> <head> <style> body{ font-family: "宋体"; font-size: 12px} table { width:100%; border-collapse:collapse; border: 1px #CC0066 solid; font-family: "宋体"; font-size: 12px} .tablehead{background-color:#CCCCFF} td{ border: 1px #CC0066 solid} </style> </head> <body> <xsl:for-each select="table"> 数据表 <b><xsl:value-of select="translate(@tablename,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" /></b> 结构 共 <xsl:value-of select="count(*)" /> 个字段 <br /> <table > <tr ="tablehead"> <td>字段名</td> <td>类型</td> <td>长度</td> </tr> <xsl:for-each select="*"> <tr> <td> <xsl:value-of select="@fieldname" /> </td> <td> <xsl:value-of select="@fieldtype" /> </td> <td> <xsl:value-of select="@fieldwidth" /> </td> </tr> </xsl:for-each> </table> <p /><hr /> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
################################ temp_Java_Struct.xml ####################################################################### <?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <html><head></head><body> <xsl:for-each select="*/table"> <br />-------------- 文件名 <xsl:value-of select="@tablename" />.java ----------------------------- <pre style=" background-color:gainsboro"> package com.haitai.emr.struct; import java.sql.*; import java.io.*; /** <xsl:value-of select="@cname" /> * @author 代码生成器 */ public <xsl:value-of select="@tablename" /> implements Serializable { // 定义数据库字段变量 //////////////////////////////////////////////////////////////// <xsl:for-each select="*"> <xsl:variable name="javatype"> <xsl:choose> <xsl:when test="@is ='1'">String </xsl:when> <xsl:when test="boolean('true')" > </xsl:when> </xsl:choose> </xsl:variable> <xsl:variable name="lowfieldname"> <xsl:value-of select="translate(@fixname,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" /> </xsl:variable> private <xsl:value-of select="$javatype" /> <xsl:text disable-output-escaping="yes"></xsl:text><xsl:value-of select="$lowfieldname" /> ; // 字段 <xsl:value-of select="@cname" /> </xsl:for-each> public final String SELECT = "Select <xsl:for-each select="*"> <xsl:value-of select="normalize-space(@fieldname)" /> <xsl: test="position != last ">,</xsl: > </xsl:for-each> From <xsl:value-of select="@tablename" />"; /** @param conn * @exception SQLException */ public java.sql.PreparedStatement makeInsSt (java.sql.Connection conn) throws SQLException{ PreparedStatement pst=conn.prepareStatement("insert o <xsl:value-of select="@tablename" />(<xsl:for-each select="*"> <xsl:value-of select="normalize-space(@fieldname)" /> <xsl: test="position != last ">,</xsl: > </xsl:for-each>)" +"values(<xsl:for-each select="*">?<xsl: test="position != last ">,</xsl: ></xsl:for-each>)");
index=0; <xsl:for-each select="*"> pst. String( index,this.get<xsl:value-of select="@fieldname" /> ); // <xsl:value-of select="@cname" /> </xsl:for-each>
pst; } /** @param conn * @exception SQLException */ public java.sql.PreparedStatement makeUpdSt (java.sql.Connection conn) throws SQLException{ // TODO : implement PreparedStatement pst=conn.prepareStatement("update <xsl:value-of select="@tablename" /> <xsl:for-each select="*"><xsl:value-of select="normalize-space(@fieldname)" /> =? <xsl: test="position != last ">,</xsl: ></xsl:for-each>)" +"where 数据表关键字段名=?");
index=0; <xsl:for-each select="*"> pst. String( index,this.get<xsl:value-of select="@fieldname" /> ); // <xsl:value-of select="@cname" /> </xsl:for-each> //关键字 pst. String( index,this.get数据表关键字段名 );//数据表关键字段介绍说明
pst; } public String toString { // TODO : implement
<xsl:for-each select="*">"<xsl: test="position != 1">,</xsl: ><xsl:value-of select="normalize-space(@fieldname)" />="+ <xsl:value-of select="@lowfieldname" /><xsl: test="position != last "> + </xsl: > </xsl:for-each>; } // 读取和修改数据 接口 <xsl:for-each select="*"> <xsl:variable name="javatype"> <xsl:choose> <xsl:when test="@is ='1'">String</xsl:when> <xsl:when test="boolean('true')"> </xsl:when> </xsl:choose> </xsl:variable> <xsl:variable name="lowfieldname"> <xsl:value-of select="translate(@fieldname,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" /> </xsl:variable> public <xsl:value-of select="$javatype" /> get<xsl:value-of select="@fieldname" /> {
<xsl:value-of select="normalize-space($lowfieldname)" /> ; } //@param <xsl:value-of select="@cname" /> public void <xsl:value-of select="@fieldname" />(<xsl:value-of select="@javatype" /> value){ <xsl:value-of select="normalize-space($lowfieldname)" /> = value ; } </xsl:for-each> } // 类 <xsl:value-of select="@tablename" /> 定义结束 </pre> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> ######################################## temp_VB.xml ############################################################
<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" /> <xsl:template match="/"> <html> <head></head> <body> <xsl:for-each select="*/table"> <br />-------------- 文件名 <xsl:value-of select="@tablename" />.cls ----------------------------- <pre style=" background-color:gainsboro"> '****************************************************************************** '** '** 数据表 <xsl:value-of select="@cname" />[ <xsl:value-of select="@tablename" /> ]操作 ![](/icons/31078de.gif) 对象 '** '** 编制:代码生成器 '** 时间: '** '****************************************************************************** '** 定义和数据库字段对应 ![](/icons/31078de.gif) 变量 ************************************************************* private const c_TableName As String = "<xsl:value-of select="@tablename" />" '** 数据表名称 <xsl:for-each select="*"> <xsl:variable name="vbtype"> <xsl:choose> <xsl:when test="@is ='1'">String </xsl:when> <xsl:when test="boolean('true')" >Integer </xsl:when> </xsl:choose> </xsl:variable> <xsl:variable name="lowfieldname"> <xsl:value-of select="translate(@fieldname,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')" /> </xsl:variable> private m_<xsl:value-of select="@fixname" /> As <xsl:value-of select="$vbtype" /> '** 字段 <xsl:value-of select="@cname" /> </xsl:for-each>
'** 定义数据库字段属性接口 *************************************************************** Public Property Get TableName As String TableName = c_TableName End Property <xsl:for-each select="*"> <xsl:variable name="vbtype"> <xsl:choose> <xsl:when test="@is ='1'">String </xsl:when> <xsl:when test="boolean('true')" >Integer </xsl:when> </xsl:choose> </xsl:variable> '** 数据库字段 <xsl:value-of select="@cname" /> Public Property Get m<xsl:value-of select="@fieldname" /> As <xsl:value-of select="$vbtype" /> m<xsl:value-of select="@fieldname" /> = m_<xsl:value-of select="@fieldname" /> End Property Public Property Let m<xsl:value-of select="@fieldname" />(Byval Value As <xsl:value-of select="$vbtype" />) m_<xsl:value-of select="@fieldname" /> = m<xsl:value-of select="@fieldname" /> End Property </xsl:for-each> '** 获得查询所有数据使用 SQL语句 ** public Function GetBaseSQL As String GetBaseSQL ="Select <xsl:for-each select="*"> <xsl:value-of select="@fieldname" /> <xsl: test="position != last ">,</xsl: > </xsl:for-each> From " <xsl:text disable-output-escaping="yes">&</xsl:text> c_TableName End Function
'** 定义从数据库记录集获得数据 ![](/icons/31078de.gif) 思路方法 ** Public Function SelectRS(ByVal rs As ADODB.Record ) As Boolean On Error GoTo SelectErr SelectRS = False <xsl:for-each select="*"> m_<xsl:value-of select="@fixname" /> = rs.Fields(<xsl:value-of select="position -1" />).Value '** 字段 <xsl:value-of select="@cname" /> </xsl:for-each> SelectRS = True Exit Function SelectErr: SelectRS = False End Function </pre> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> ####################### temp_表介绍说明文档.xml ################################## <?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <html> <head></head> <body> <xsl:for-each select="*/table"> -------------表 <xsl:value-of select="@tablename" /> 介绍说明文档 <xsl:value-of select="count(*)" />个字段 <br /><pre style="word-wrap: -word;background-color:gainsboro"> <xsl:for-each select="*"><xsl:value-of select="@fixname" /><xsl:text disable-output-escaping="yes"> </xsl:text><xsl:value-of select="@fieldtype" /> <xsl: test="@is ='1'">(<xsl:value-of select="@fieldwidth" />)</xsl: > . <xsl:text disable-output-escaping="yes"></xsl:text> </xsl:for-each> </pre> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
####################### temp_创建表 ![](/icons/31078de.gif) SQL语句.xml ################################## <?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <html> <head></head> <body> <xsl:for-each select="*/table"> -------------创建表 <xsl:value-of select="@tablename" /> SQL语句 <xsl:value-of select="count(*)" />个字段 <br /><pre style="word-wrap: -word;background-color:gainsboro"> CREATE TABLE <xsl:value-of select="@tablename" />( <xsl:for-each select="*"> <xsl:text disable-output-escaping="yes"></xsl:text> <xsl:value-of select="@fixname" /> <xsl:value-of select="@fieldtype" /> <xsl: test="@is ='1'">(<xsl:value-of select="@fieldwidth" />)</xsl: > <xsl: test="position != last "> , </xsl: > </xsl:for-each> ) </pre> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> ####################### temp_选择表使用 ![](/icons/31078de.gif) SQL语句.xml ################################## <?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <html> <head></head> <body> <xsl:for-each select="*/table"> -------------选择表 <xsl:value-of select="@tablename" /> SQL语句 <xsl:value-of select="count(*)" />个字段 <br /><pre style="word-wrap: -word;background-color:gainsboro"> Select <xsl:for-each select="*"> <xsl:text disable-output-escaping="yes"></xsl:text> <xsl:value-of select="normalize-space(@fieldname)" /> <xsl: test="position != last "> , </xsl: > </xsl:for-each> From <xsl:value-of select="@tablename" /></pre> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
相关文章
读者评论
发表评论
|
|