博图VBS修改SQLServer数据
Sub VBFunction_SaveVal()
'提示:
' 1. 使用 <CTRL+SPACE> 或 <CTRL+I> 快捷键打开含所有对象和函数的列表
' 2. 使用 HMI Runtime 对象写入代码。
' 示例:HmiRuntime.Screens("Screen_1")。
' 3. 使用 <CTRL+J> 快捷键创建对象引用。
'从此位置起写入代码:
Dim connSave '定义类对象
Dim SConSave '定义数据库连接字符串
Dim oRsSave '定义获取到的数据集
Dim oComSave
'---------打开数据库 -----------'
SConSave= "Provider=SQLOLEDB; Integrated Security =SSPI;Persist Security Info=True;Initial Catalog=PlanCheck;Data Source=DESKTOP-OCMKPGO;uid=sa;pwd=password"
Set connSave=CreateObject("ADODB.Connection")
connSave.ConnectionString = SConSave
connSave.CursorLocation = 3
connSave.Open
Set oRsSave = CreateObject("ADODB.Recordset")
Set oComSave = CreateObject("ADODB.Command")
oComSave.ActiveConnection = connSave
oComSave.CommandType = 1
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_Error").ProcessValue &" WHERE iItem_name = 'error_val'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ1").ProcessValue &" WHERE iItem_name = 'A_Z1'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ2").ProcessValue &" WHERE iItem_name = 'A_Z2'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ3").ProcessValue &" WHERE iItem_name = 'A_Z3'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ4").ProcessValue &" WHERE iItem_name = 'A_Z4'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("io_az5").ProcessValue &" WHERE iItem_name = 'A_Z5'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ6").ProcessValue &" WHERE iItem_name = 'A_Z6'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ7").ProcessValue &" WHERE iItem_name = 'A_Z7'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ8").ProcessValue &" WHERE iItem_name = 'A_Z8'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_BY1").ProcessValue &" WHERE iItem_name = 'B_Y1'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_BY2").ProcessValue &" WHERE iItem_name = 'B_Y2'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_BY3").ProcessValue &" WHERE iItem_name = 'B_Y3'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_BY4").ProcessValue &" WHERE iItem_name = 'B_Y4'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_CY1").ProcessValue &" WHERE iItem_name = 'C_Y1'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_CY2").ProcessValue &" WHERE iItem_name = 'C_Y2'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("io_CY3").ProcessValue &" WHERE iItem_name = 'C_Y3'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_CY4").ProcessValue &" WHERE iItem_name = 'C_Y4'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ1").ProcessValue &" WHERE iItem_name = 'D_Z1'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ2").ProcessValue &" WHERE iItem_name = 'D_Z2'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ3").ProcessValue &" WHERE iItem_name = 'D_Z3'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ4").ProcessValue &" WHERE iItem_name = 'D_Z4'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ5").ProcessValue &" WHERE iItem_name = 'D_Z5'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ6").ProcessValue &" WHERE iItem_name = 'D_Z6'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ7").ProcessValue &" WHERE iItem_name = 'D_Z7'"
Set oRsSave = oComSave.Execute
oComSave.CommandText = "UPDATE setting SET item_value = "& HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ8").ProcessValue &" WHERE iItem_name = 'D_Z8'"
Set oRsSave = oComSave.Execute
'---------关闭数据库-----------'
Set oRsSave = Nothing
Set oComSave = Nothing
connSave.Close
Set connSave = Nothing
HmiRuntime.Screens("画面_设置").ScreenItems("IO_Error").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ1").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ2").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ3").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ4").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("io_az5").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ6").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ7").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_AZ8").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_BY1").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_BY2").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_BY3").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_BY4").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_CY1").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_CY2").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("io_CY3").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_CY4").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ1").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ2").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ3").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ4").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ5").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ6").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ7").Enabled = True
HmiRuntime.Screens("画面_设置").ScreenItems("IO_DZ8").Enabled = True
SmartTags("IsLoadSettingVal") = True
End Sub