Sub Datamanage(strSQL)
Dim objConnection
Dim strConnectionString,objCommand,rec
Dim str
Dim my
strConnectionString = "DRIVER={SQL server};SERVER=TGLJDATAPCS\WINCC;DATABASE=TGLJPCSDB"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With
On Error Resume Next
objCommand.Execute
If Err.number<>0 Then
Err.raise 6
End If
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Sub
请高手帮帮忙 最好能每一句都注明下含义
看了几天VB的书 还是迷茫啊~!~!~!
最佳答案
Sub Datamanage(strSQL) -过程名
Dim objConnection-定义连接对象变量
Dim strConnectionString,objCommand,rec-定义连接字符串,comand对象变量
Dim str-变量
Dim my-变量
strConnectionString = "DRIVER={SQL server};SERVER=TGLJDATAPCS\WINCC;DATABASE=TGLJPCSDB" -连接字符串赋值
Set objConnection = CreateObject("ADODB.Connection")-创建连接对象
objConnection.ConnectionString = strConnectionString 设置连接对象的连接属性
objConnection.Open 打开连接
Set objCommand = CreateObject("ADODB.Command") 创建command对象
With objCommand
.ActiveConnection = objConnection -给command对象的连接属性赋值,因为command的连接属性是连接对象类型的,所以objConnection直接赋值过去
.CommandText = strSQL -所要执行的sql语句
End With
On Error Resume Next -出错处理
objCommand.Execute-执行连接及SQL
If Err.number<>0 Then
Err.raise 6
End If
Set objCommand = Nothing 释放对象
objConnection.Close -关闭连接
Set objConnection = Nothing -释放对象
End Sub
结束!!!!
提问者对于答案的评价:
非常感谢
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc274484.html