使用SQL无源连接,须先点 工程 菜单 选择 引用 然后勾选Microsoft ActiveX Data Objects 2.8 Library和Microsoft ActiveX Data Objects Recordset 2.8 Library

Dim db As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim sql As StringDim c As IntegerDim d As IntegerDim b As StringPrivate Sub Form_Load()db.Open "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;InitialCatalog=DATABASENAME;Data Source=192.172.0.2"End SubPrivate Sub Timer1_Timer()c = c + 1If c Mod 60 = 0 Then d = d + 1 rs.Open "update mes_sn set fnextterminalid=1098 where fworkorderno='m3112039405' and fnextterminalid=1097 andfcurrentterminalid=1099", db b = Str(d) Label1.Caption = "已经执行第" + b + "次"End IfEnd Sub