使用计时器将数据保存在数据库中? [英] save data in database by using timer ?

查看:85
本文介绍了使用计时器将数据保存在数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家



i有一个名为trend的访问数据库,还有一个带有两个字段的表来存储当前的日期和时间。

i在表单中有一个计时器控件,我想每10秒存储当前日期和时间。

datetextbox和timetextbox被绑定到我的数据库:

所以我做了如下所示:

 Private Sub Form1_Load(sender as  Object ,e As EventArgs)Handles MyBase.Load 
Me.TemplogTableAdapter.Fill (Me.TrendDataSet.templog)
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(发送者为对象,e As EventArgs)处理Timer1.Tick
Me.TemplogBindingSource.AddNew()
DateTextBox.Text = DateString
TimeTextBox.Text = TimeString
Me.Validate()
Me.TemplogBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.TrendDataSet)
结束Sub



表单中的所有内容在运行时都是正确的,但数据不会保存在数据库中。

解决方案

< blockquote>您好


请跟踪您的计时器事件并确保生成的查询(Sql Insert)是有效的,您可以通过dbms(sql server或access或...)查询来测试它设计师作为一种简单的方式:



1-跟踪计时器事件

2-缓存生成的查询在这里

来自DBMS查询设计师的3-复制/过去查询

4-在DBMS模式下运行查询(直接在数据库上)



如果一切都是好的,所以你在数据访问层有问题;)请按照这个链接并使用ADO.net原生对象来实现你的数据访问层。



带定时器的轮询数据库 [ ^ ]

使用C#读取,插入,更新和删除简单的ADO.NET数据库。 [ ^ ]



最好的问候


Hi experts

i have an access database called "trend" and there is a table with tow field to store current date and time.
i have a timer control in the form and i want to store current date and time every 10 sec .
datetextbox and timetextbox are binded to my database :
so i did as below :

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.TemplogTableAdapter.Fill(Me.TrendDataSet.templog)
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Me.TemplogBindingSource.AddNew()
        DateTextBox.Text = DateString
        TimeTextBox.Text = TimeString
        Me.Validate()
        Me.TemplogBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.TrendDataSet)
    End Sub


in the form all thing is correct at runtime but data does'nt save in database.

解决方案

Hi
Please trace your timer event and be sure generated query(Sql Insert) is a valid you can test it by your dbms(sql server or access or ...) query designer as a simple way:

1- trace timer event
2- cache generated query at here
3- copy/past query from DBMS query designer
4- run the query in DBMS mode (directly on database)

If everything is ok so you have a problem in data access layer ;) please follow of this link and used ADO.net native objects for implementation your data access layer.

Polling Database with Timer[^]
Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]

Best Regards


这篇关于使用计时器将数据保存在数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆