vbs mysql 读数据库_vbs中操作数据库、读写文件、XML

'数据库连接

'Option explicit

'Dim cnn,rst,strCnn,str,i

'Dim ParamCount,ParamIndex,ParamName,ParamValue

'strCnn="Provider=SQLOLEDB.1;Password=Atlas2012;Persist Security Info=True;User ID=sa;Initial Catalog=aaa;Data Source=127.0.0.1"

'Set cnn=CreateObject("ADODB.Connection")

'cnn.Open strCnn

'Set rst=CreateObject("ADODB.RecordSet")

'rst.Open "select * from groupinfo ",cnn

'rst.MoveFirst

' i=1

'Do while not rst.EOF

' ' str=str&rst.Fields("Tag_patient_name")&vbcrlf

' datatable.SetCurrentRow(i)

' str=rst.Fields("GroupID") &"     "&rst.Fields("GroupName")

'     datatable.Value(1,"Action1")=str

' rst.MoveNext

' i=i+1

'Loop

''msgbox str

'rst.Close

'cnn.Close

'Set rst=nothing

'Set cnn=nothing

'--文本文件读写’

'Option explicit

'Dim fso,file,i,msg

'Set fso=createObject("Scripting.FileSystemObject")

'If fso.FileExists("c:\test.txt") then

'   fso.DeleteFile("c:\test.txt")

'   msgbox("删除成功!")

'else

'  Set file=fso.CreateTextFile("c:\test.txt",2)

'  msgbox("创建成功!")

'end if

'For i=1 to 5

'    file.Write(i)

' 'writeline()后面要加换行符

'Next

'msgbox("写文件成功!")

'

'Set file=fso.OpenTextFile("C:\test.txt",1)

''while(not File.AtEndOfStream)

'' msg=msg&file.ReadLine&vbcrlf

''wend

'msg=file.ReadAll

'msgbox("读文件:"&msg)

'file.Close

'Set file=nothing

'Set fso=nothing

'Option explicit

'Dim xlApp,xlWorkBook,xlSheet,row,col

'Set xlApp=CreateObject("Excel.Application")

'xlApp.Visible=true

'Set xlWorkBook=xlApp.Workbooks.Open("c:\data.xlsx")

'Set xlSheet=xlWorkBook.Sheets("Sheet1")

'For row=1 to 10

'  For  col=1 to 3

'   xlSheet.Cells(row,col)=row+col

'  Next

'Next

'xlWorkBook.Save

'xlWorkBook.Close

'xlApp.Quit

'Set xlSheet=nothing

'Set xlWorkBook=nothing

'Set xlApp=nothing

'播放音乐

'Dim wmp

'Set wmp=createobject("WMPlayer.ocx")

'wmp.openPlayer("c:\滴答.mp3")

'Do  until wmp.playState=1

'    WScript.Sleep 1000

'Loop

'xml文件读写

Option explicit

Dim xmldoc,xmlroot,nodelist,i

Set xmldoc=CreateObject("Microsoft.XMLDOM") '创建xml dom对象

xmldoc.async=false   '控制加载模式为同步模式(xml树加载完毕后再执行后续代码)

xmldoc.load  "c:\aa.xml"  '加载文档

If   xmldoc.parseError.errorCode<>0  Then

msgbox "xml load fail"

End If

Set xmlroot=xmldoc.documentElement  '获取节点

' MsgBox xmlroot.text

If  xmlroot.hasChildNodes Then

For each nodelist  in xmlroot.ChildNodes

msgbox nodelist.getAttribute("Sex") '读属性值

'MsgBox nodelist.text '读所有元素值

For i=0 to (nodelist.childNodes.length-1) '读每个元素

msgbox(nodelist.childNodes(i).nodeName&": "&nodelist.childNodes(i).text)

Next

Next

End If

对应XML文件:

小陈

福建

110

小陈@gmail.com

小林

广州

112

小林@gmail.com

自己练习的,可以直接运行,保存下来。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值