VB6如何利用ADO控件实现SQL数据库中表内容的添加功能?测试程序敬请指正。

ycxylq 2014-08-29 10:47:40
完成功能:实现SQL数据test中的table1表中的内容1分钟记录一次。
测试代码如下所示:
Dim a, b As Integer
Dim number As Integer

Private Sub Form_Load()
b = 10
a = 1
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Dim c As Integer
Dim t As Integer
c = Int((b - a + 1) * Rnd + a)
Text1.Text = c
If t < 60 Then
t = t + 1
Else
t = 0
number = number + 1
Dim r As New Recordset
Dim com As Connection
Set com = New ADODB.Connection
com.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=GUANLV02\WINCC"
com.Execute "insert Table1(time,value) values('number','c')"
End If
End Sub
不知哪块出错,怎么表中不见添加的记录?敬请指正。
...全文
245 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
of123 2014-09-02
  • 打赏
  • 举报
回复
把 Dim com As Connection 放到公共段。 把 Set com = New ADODB.Connection com.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=GUANLV02\WINCC" 放到 Form_Load 段。 在 Form_Unload() 中添加 com.Close Set com = Nothing 另外,如果你的代码确如你贴出的情况,可将 Dim r As New Recordset 删除。
三楼の郎 2014-08-31
  • 打赏
  • 举报
回复
insert into Table1(time,value) values(“ & number & ",'" & c & "')
三楼の郎 2014-08-31
  • 打赏
  • 举报
回复
insert into Table1(time,value) values('number','c')

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧