搬家第一天-3.WinccV7.3创建数据库Mydatabase

Sub OnClick(ByVal Item)   
Dim ors,conn,con,ssql,ocom
Dim PCName
PCName=HMIRuntime.Tags("@LocalMachineName").Read
con="Provider = SQLOLEDB.1;password = sa;user id = sa;Initial Catalog =master;Data Source = " & PCName & "\WINCC"
''con="Provider = SQLOLEDB.1;password = sa;user id = sa;Data Source = " & PCName & "\WINCC"

Set conn=CreateObject("ADODB.Connection")
conn.ConnectionString=con
conn.Cursorlocation=3
conn.open
ssql="select * from master.dbo.sysdatabases where [name] ='MyDataBase'"
''ssql="select name from dbo.sysdatabases where name ='MyDataBase'"
Set ors=CreateObject("ADODB.RecordSet")
Set ocom=CreateObject("ADODB.Command")
Set ocom.activeconnection=conn
ocom.CommandType=1
ocom.CommandText=ssql
Set ors=ocom.Execute
If ors.recordcount>0 Then
   Msgbox "MyDataBase已经存在,无需创建"
Else

ssql="Create Database MyDatabase"
ocom.CommandText=ssql
Set ors=ocom.Execute

Msgbox "MyDatabase创建完毕"
End If
Set ors=Nothing
conn.close
Set conn=Nothing
End Sub

上一篇:不同版本AutoCAD的ProgID


下一篇:(精华)2020年8月15日 C#基础知识点 Unity容器的底层的实现方式