| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2959 人关注过本帖
标题:如何生成XML文件
只看楼主 加入收藏
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
那你就msgbox "<field name=""" & s_FieldName(j) & """> " & rs.Fields(j).Value & "</field>"
看看显示出来是什么.
我运行我写的没错.

我的msn: myfend@
2007-09-18 10:47
junxi1
Rank: 1
等 级:新手上路
威 望:1
帖 子:213
专家分:0
注 册:2007-9-17
收藏
得分:0 

msgbox "<field name=""" & s_FieldName(j) & """> " & rs.Fields(j).Value & "</field>"
运行是没有错,但我要写在XML文件中。
 
把msgbox换为print #1, 就会出现错误了。
提示是:
文本内容中发现无效字符。
<field name="sname">


foreach( in ){ }
2007-09-18 11:01
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
没有人说msgbox会有错.
我是叫你看看它显示出来是什么.

我的msn: myfend@
2007-09-18 11:06
junxi1
Rank: 1
等 级:新手上路
威 望:1
帖 子:213
专家分:0
注 册:2007-9-17
收藏
得分:0 
显示出来的就是我想的结果

<field name="sno">2</field>

foreach( in ){ }
2007-09-18 11:23
junxi1
Rank: 1
等 级:新手上路
威 望:1
帖 子:213
专家分:0
注 册:2007-9-17
收藏
得分:0 

原来是因为rs.Fields(j).Value的值不能是汉字,只要是出现汉字,就提示发现无效字符
如何才可以显示汉字


foreach( in ){ }
2007-09-18 11:54
junxi1
Rank: 1
等 级:新手上路
威 望:1
帖 子:213
专家分:0
注 册:2007-9-17
收藏
得分:0 

测试通过。代码为:
Option Explicit

Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim ConString As String
Dim strTableName As String
Dim str As String
Dim sa As String
Dim pwd As String
Dim data1e As String

str = "192.168.0.1"
pwd = ""
data1e = "wh3"
ConString = "driver={sql server}; server=" & str & ";uid=sa ; pwd=" & pwd & ";database=" & data1e & ""

conn.Open ConString

Open "f:\d\x.xml " For Output As #1
Print #1, "<?xml version=""1.0"" encoding=""gb2312"" ?>"
Print #1, "<result>"
Close
strTableName = "student"
toXml strTableName, conn, "主表"

strTableName = "uses"
toXml strTableName, conn, "副表"
conn.Close

Open "f:\d\x.xml " For Append As #1
Print #1, "</result>"
Close
End Sub

Private Sub toXml(tableName As String, con As ADODB.Connection, t As String)
Dim rs As New ADODB.Recordset
Dim i As Integer
Dim s As Integer
Dim j As Integer
Dim str As String
Dim ss As Variant
str = "select * from " & tableName & ""
rs.CursorLocation = adUseClient

rs.Open str, con, adOpenKeyset, adLockReadOnly, adCmdText
s = rs.Fields.Count
ReDim s_FieldName(s) As String

For i = 0 To s - 1
s_FieldName(i) = rs.Fields(i).Name
Next

Open "f:\d\x.xml" For Append As #1

Print #1, "<table Name = """ & tableName & "为 " & t & """> "
For i = 0 To rs.RecordCount - 1
Print #1, "<row>"
For j = 0 To s - 1
ss = rs.Fields(j).Value
Print #1, "<field name=""" & s_FieldName(j) & """ value=""" & ss & """></field>"
Next
Print #1, "</row>"
rs.MoveNext
Next
Print #1, "</table>"
Close
rs.Close



End Sub


[此贴子已经被作者于2007-9-19 15:47:01编辑过]


foreach( in ){ }
2007-09-19 15:45
快速回复:如何生成XML文件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027204 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved