odbc和ado mysql_ODBC或ADO与数据库的关联

我想通过VB脚本建立与数据库关联,将数据存入。1、西门子技术人员曾经暗示通过ODBC或ADO打开或关闭数据库的执行时间很长。因为我信息存储的时间间隔最短2S,所以想问一下能不能通过这个方式将数据存入。2、西门子技术人员提供的程序如下:ODBC:'VBS108DimobjConnectionDimobjCommandDimobjRecordsetDimstrConnectionStringDimstrSQLDimlngValueDimlngCountstrConnectionString="Provider=MSDASQL;DSN=riqi;UID=;PWD=;"lngValue=Now’Date/Time/NowstrSQL="INSERTINTOTable1(riqi)VALUES('"&lngValue&"')"’字符型SetobjConnection=CreateObject("ADODB.Connection")objConnection.ConnectionString=strConnectionStringobjConnection.OpenSetobjRecordset=CreateObject("ADODB.Recordset")SetobjCommand=CreateObject("ADODB.Command")objCommand.ActiveConnection=objConnectionobjCommand.CommandText=strSQLobjCommand.ExecuteSetobjCommand=NothingobjConnection.CloseSetobjRecordset=NothingSetobjConnection=Nothing或ADO:DimobjConnectionDimstrConnectionStringDimlngValueDimstrSQLDimobjCommandstrConnectionString="Provider=SQLOLEDB.1;IntegratedSecurity=SSPI;PersistSecurityInfo=False;UserID=sa;InitialCatalog=WinCC;DataSource=LEMONVISTA"lngValue=HMIRuntime.Tags("AccessTag").ReadstrSQL="INSERTINTOWINCC_DATA(TagValue)VALUES("&lngvalue&")"’数值SetobjConnection=CreateObject("ADODB.Connection")objConnection.ConnectionString=strConnectionStringobjConnection.OpenSetobjCommand=CreateObject("ADODB.Command")WithobjCommand.ActiveConnection=objConnection.CommandText=strSQLEndWithobjCommand.ExecuteSetobjCommand=NothingobjConnection.CloseSetobjConnection=Nothing3、我的程序是:DimobjConnectionDimobjCommandDimobjRecordsetDimstrConnectionStringDimstrSQLDimlngValueDimlngCountDimzhiDimGSetzhi=HMIRuntime.Tags("值")SetG=HMIRuntime.Tags("归档")G.ReadIfG.Value=1ThenSetobjConnection=CreateObject("ADODB.Connection")strConnectionString="Provider=WINCCOLEDBProvider.1;Catalog=CC_TEST_11_01_05_14_55_59R;DataSource=.\WINCC"MsgBox("00000")lngValue=HMIRuntime.Tags("名称").readobjConnection.ConnectionString=strConnectionStringMsgBox("11111")objConnection.OpenstrSQL="INSERTINTOTable_2(MC)VALUES('"&lngValue&"')"'字符型SetobjRecordset=CreateObject("ADODB.Recordset")SetobjCommand=CreateObject("ADODB.Command")objCommand.ActiveConnection=strConnectionStringobjCommand.CommandText=strSQLMsgBox("66666")objRecordset=objCommand.ExecuteMsgBox("77777")SetobjCommand=NothingobjConnection.CloseSetobjRecordset=NothingSetobjConnection=NothingMsgBox("55555")zhi.Readzhi.Value=zhi.Value+1zhi.WriteEndIf在调试中“objRecordset=objCommand.Execute”后不能往下执行,不能弹出77777的窗口。我看过很多通过ODBC建立与数据库链接的程序,大体上都是一样的,ADO的程序跟ODBC的差不多能详细说明链接和调试方法吗?

问题补充:我建立与数据库的链接,目的是要向数据库中写入数据,当新的数据来时自动添加一行,一直就这么存储下去。我并不需要查询数据库里面的数据,然后写入EXCEL表格。能不能确认几个信息:1、与数据库链接时,用户名,密码的表达方式。2、数据库链接的名字,表名等的表达方式(这个表格是在数据库里单独建立吗?我是单独先建了一个),如:CC_test110_11_01_20_10_33_36R,Table_2。3、变量的链接或表达方式,如字符串或数值的表达方式。4、ODBC等有关的操作信息等等我没考虑到的关键信息?非常感谢
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值