定时检测vb程序
想要每十分钟对数据进行评价,然后将评价结果存入数据库,代码如下PrivateSubTimer1_Timer()Text7.Text=Date$'获得时间日期Text8.T...
想要每十分钟对数据进行评价,然后将评价结果存入数据库,代码如下
Private Sub Timer1_Timer()
Text7.Text = Date$ '获得时间日期
Text8.Text = Time$
On Error Resume Next
Dim tmChk As Date
tmChk = Time
If (Minute(tmChk) = 10 Or Minute(tmChk) = 20 Or Minute(tmChk) = 30 Or Minute(tmChk) = 40 Or Minute(tmChk) = 50 Or Minute(tmChk) = 0) And Second(tmChk) = 0 Then
sum1 = Val(Text1.Text) * 0.4587 + Val(Text2.Text) * 0.1665 + Val(Text3.Text) * 0.1609 + Val(Text4.Text) * 0.0433 + Val(Text5.Text) * 0.0427 + Val(Text9.Text) * 0.0428 + Val(Text11.Text) * 0.0425 + Val(Text12.Text) * 0.0426
If sum1 <= 3 Then
Text6.Text = "贫营养化"
ElseIf (sum1 > 3 And sum1 <= 4) Then
Text6.Text = "贫中营养化"
ElseIf (sum1 > 4 And sum1 <= 5) Then
Text6.Text = "中营养化"
ElseIf (sum1 > 5 And sum1 <= 6) Then
Text6.Text = "中富营养化"
ElseIf (sum1 > 6 And sum1 <= 7) Then
Text6.Text = "富营养化"
Else
Text6.Text = "重富贫营养化"
End If
Adodc1.Recordset.MoveLast
sn = Val(Adodc1.Recordset("ID"))
Text10 = sn + 1
Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\szjc.mdb;Persist Security Info=False"
Con.Open
Set Rs = Con.Execute("insert into sheet2 (ID,PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values('" + Text10 + "','" + Text1 + "','" + Text2 + "','" + Text3 + "','" + Text4 + "','" + Text5 + "','" + Text9 + "','" + Text11 + "','" + Text12 + "','" + Text7 + "','" + Text8 + "','" + Text6 + "')")
Con.Close
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\szjc.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from sheet2 order by ID"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
现在可以实现每十分钟评价一次,但为什么存不进数据库啊!!!请高人帮忙~ 展开
Private Sub Timer1_Timer()
Text7.Text = Date$ '获得时间日期
Text8.Text = Time$
On Error Resume Next
Dim tmChk As Date
tmChk = Time
If (Minute(tmChk) = 10 Or Minute(tmChk) = 20 Or Minute(tmChk) = 30 Or Minute(tmChk) = 40 Or Minute(tmChk) = 50 Or Minute(tmChk) = 0) And Second(tmChk) = 0 Then
sum1 = Val(Text1.Text) * 0.4587 + Val(Text2.Text) * 0.1665 + Val(Text3.Text) * 0.1609 + Val(Text4.Text) * 0.0433 + Val(Text5.Text) * 0.0427 + Val(Text9.Text) * 0.0428 + Val(Text11.Text) * 0.0425 + Val(Text12.Text) * 0.0426
If sum1 <= 3 Then
Text6.Text = "贫营养化"
ElseIf (sum1 > 3 And sum1 <= 4) Then
Text6.Text = "贫中营养化"
ElseIf (sum1 > 4 And sum1 <= 5) Then
Text6.Text = "中营养化"
ElseIf (sum1 > 5 And sum1 <= 6) Then
Text6.Text = "中富营养化"
ElseIf (sum1 > 6 And sum1 <= 7) Then
Text6.Text = "富营养化"
Else
Text6.Text = "重富贫营养化"
End If
Adodc1.Recordset.MoveLast
sn = Val(Adodc1.Recordset("ID"))
Text10 = sn + 1
Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\szjc.mdb;Persist Security Info=False"
Con.Open
Set Rs = Con.Execute("insert into sheet2 (ID,PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values('" + Text10 + "','" + Text1 + "','" + Text2 + "','" + Text3 + "','" + Text4 + "','" + Text5 + "','" + Text9 + "','" + Text11 + "','" + Text12 + "','" + Text7 + "','" + Text8 + "','" + Text6 + "')")
Con.Close
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\szjc.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from sheet2 order by ID"
Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
End Sub
现在可以实现每十分钟评价一次,但为什么存不进数据库啊!!!请高人帮忙~ 展开
3个回答
展开全部
首先,你的SQL语句引用的所有文本框中的数据时都缺少了.Text属性,应该如写法:
Set Rs = Con.Execute("insert into sheet2 (ID,PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values('" + Text10.text + "','" + Text1.text + "','" + Text2.text + "','" + Text3.text + "','" + Text4.text + "','" + Text5.text + "','" + Text9.text + "','" + Text11.text + "','" + Text12.text + "','" + Text7.text + "','" + Text8.text + "','" + Text6.text + "')")
其次:
1 如果你的数据库字段ID是自动编号的,则在SQL语句中就不要写插入ID字段的数据,如
Set Rs = Con.Execute("insert into sheet2 (PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values('" + Text1.text + "','" + Text2.text + "','" + Text3.text + "','" + Text4.text + "','" + Text5.text + "','" + Text9.text + "','" + Text11.text + "','" + Text12.text + "','" + Text7.text + "','" + Text8.text + "','" + Text6.text + "')")
2 如果你的ID字段不是自动编号的,则检查你的数据库中的所有字段的数据类型,凡是数字型数据字段的,你的SQL语句中VALUES中对应的值就不能用单引号括起来,比如ID字段是数字型的字段,那应该这么写:
Set Rs = Con.Execute("insert into sheet2 (ID,PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values(" + Text10.text + ",'" + Text1.text + "','" + Text2.text + "','" + Text3.text + "','" + Text4.text + "','" + Text5.text + "','" + Text9.text + "','" + Text11.text + "','" + Text12.text + "','" + Text7.text + "','" + Text8.text + "','" + Text6.text + "')")
Set Rs = Con.Execute("insert into sheet2 (ID,PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values('" + Text10.text + "','" + Text1.text + "','" + Text2.text + "','" + Text3.text + "','" + Text4.text + "','" + Text5.text + "','" + Text9.text + "','" + Text11.text + "','" + Text12.text + "','" + Text7.text + "','" + Text8.text + "','" + Text6.text + "')")
其次:
1 如果你的数据库字段ID是自动编号的,则在SQL语句中就不要写插入ID字段的数据,如
Set Rs = Con.Execute("insert into sheet2 (PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values('" + Text1.text + "','" + Text2.text + "','" + Text3.text + "','" + Text4.text + "','" + Text5.text + "','" + Text9.text + "','" + Text11.text + "','" + Text12.text + "','" + Text7.text + "','" + Text8.text + "','" + Text6.text + "')")
2 如果你的ID字段不是自动编号的,则检查你的数据库中的所有字段的数据类型,凡是数字型数据字段的,你的SQL语句中VALUES中对应的值就不能用单引号括起来,比如ID字段是数字型的字段,那应该这么写:
Set Rs = Con.Execute("insert into sheet2 (ID,PH,溶解氧,氨氮,温度,叶绿素,高锰酸钾,总磷,总氮,日期,时间,评价) values(" + Text10.text + ",'" + Text1.text + "','" + Text2.text + "','" + Text3.text + "','" + Text4.text + "','" + Text5.text + "','" + Text9.text + "','" + Text11.text + "','" + Text12.text + "','" + Text7.text + "','" + Text8.text + "','" + Text6.text + "')")
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询