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

搬家第一天-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

标签:Set,WinccV7.3,ocom,Mydatabase,数据库,ors,CreateObject,sa,conn
来源: https://www.cnblogs.com/fishingsriver/p/14342881.html