各位大侠,vbs脚本怎样读取SQL2005中的数据呀,请大家指点一下,小弟急用呀,最好能给个例程看看,谢谢!
可以在下面回答我,也可以发到我的邮箱,jinhui-zou@163.com
最佳答案
转载另一位兄弟的答案:
写入
Dim strcn,cn,a,b,c, d
Dim is_SQL,rscom
Set cn=CreateObject("ADODB.Connection")
Set rscom=CreateObject("ADODB.Recordset")
a=HMIRuntime.Tags("text").Read
b=HMIRuntime.Tags("GONG").Read
c=HMIRuntime.Tags("text2").Read
d=FormatDateTime(Now(),0)
strcn="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CC_tai3_07_06_13_10_31_54R;Data Source=.\WINCC"
cn.ConnectionString=strcn
is_SQL ="insert into panpi(原料,长,宽,时间 ) ValUES (''"& a &"'',''"& b &"'',''"& c &"'',''"& d &"'')"
cn.open
cn.Execute is_SQL
cn.Close
LISTVIEW读出
Dim gocn, gorsAuthors, gorsAuthorsChange, a
Set gocn = CreateObject("ADODB.Connection")
Set gorsAuthors= CreateObject("ADODB.Recordset")
gocn.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=CC_tai3_07_06_13_10_31_54R;Data Source=.\WinCC"
gorsAuthors.open "SELECT * FROM panpi where [时间] between ''2007-4-1 11:12:13'' and ''2007-7-2 10:12:12'' and 长 =4 order by 时间",gocn, 1, 3
Dim ListView1
Set ListView1=ScreenItems("ListView1")
ListView1.ListItems.clear
ListView1.ColumnHeaders.clear
ListView1.ColumnHeaders.Add, ,"NO.",30
ListView1.ColumnHeaders.Add, , CStr(gorsAuthors.Fields(0).Name),70
ListView1.ColumnHeaders.Add, , CStr(gorsAuthors.Fields(1).Name),150
ListView1.ColumnHeaders.Add, , CStr(gorsAuthors.Fields(2).Name),150
ListView1.ColumnHeaders.Add, , CStr(gorsAuthors.Fields(3).Name),150
Dim row
Dim oItem
row = 0
Do While gorsAuthors.EOF = False
row = row + 1
If row < 10 Then
row = "0" & Trim(row)
End If
Set oItem=ListView1.ListItems.Add()
oItem.Text = Left( CStr(row),5)
oItem.SubItems(1) = CStr(gorsAuthors.Fields(0).Value)
oItem.SubItems(2) = CStr(gorsAuthors.Fields(1).Value)
oItem.SubItems(3) = CStr(gorsAuthors.Fields(2).Value)
oItem.SubItems(4) = CStr(gorsAuthors.Fields(3).Value)
gorsAuthors.MoveNext
Loop
提问者对于答案的评价:
我已经能够读取sql数据了,不过还是谢谢你的回答,我会好好看看你的代码,学习一下
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc277136.html