技术论坛

 vbs accsee 数据库编程 分享

返回主题列表
作者 主题
flyfeky
侠士

经验值:1427
发帖数:157
精华帖:0
楼主    2021-08-22 14:50:47
主题:vbs accsee 数据库编程 分享

vbs 脚本看着易用,但对角本不熟悉 ,还是走了很多弯路,   一些功能都是试验得到的。 

access归档, 就SQL语句, 本人就搞了三四天才有头绪 。

Set objConnection = CreateObject("ADODB.Connection")

objConnection.ConnectionString = strConnectionString

objConnection.Open

    If (objConnection.State = 0) Then 

        MsgBox "连接数据库失败!" 

    End If 

Set objCommand = CreateObject("ADODB.Command")

With objCommand

.ActiveConnection = objConnection

.CommandText = strSQL

End With

objCommand.Execute


MsgBox (Err.Number)

    If Err.Number = 0 Then

        MsgBox "执行插入成功"

    Else

        MsgBox "执行插入失败"

    End If


Set objCommand = Nothing

objConnection.Close

Set objConnection = Nothing



分享 :  1.特别两点,  数据库是否连接上, SQL语句是否执行正确,  代码在上面,也是我在网上百度来的。

              2,sql语句是否正确, 这个可能要一点点试  。 第一条语句  时间日期查询 

  strSQL = "select * from Cassette where  日期时间  between #"&StartTime&"# and #"&EndTime&"#  "    

结合1 会返回查询正确。   3  ,插入语句  strSQL = "INSERT INTO Cassette (组号,花篮ID1,称重1,花篮ID2,称重2,花篮ID3,称重3,花篮ID4,称重4,日期时间,TankID,标记)values('"&ZH&"','"&Cassette1&"','"&Weigh1&"','"&Cassette2&"','"&Weigh2&"','"&Cassette3&"','"&Weigh3&"','"&Cassette4&"','"&Weigh4&"','"&Time1&"',"&TankID&","&Lable&");"  

实际执行的语句,  也就是除了数字,都要有单引号,最后执行的语句,否则就报错,  数字可以没有,尽管我加上了。

以后VBS的问题 ,继续 在此讨论。

      


bilibili 工控贵族
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。