每10毫秒更新一次数据表 [英] updating datatable every 10 ms

查看:251
本文介绍了每10毫秒更新一次数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有10个标签,每个标签由不同的数值组成,每2 ms更新一次。现在我试图将这些数据逐行保存到我的访问数据库10 ms。每隔1秒,我的访问数据库应该用100行数据更新。我在计时器内使用下面的代码,但我只能设法插入20行。有任何可能的方法来实现这一点,或者我我使用了错误的方法。请帮助我。



谢谢



Hi,
I have 10 labels each labels consists of different numeric values which gets updated every 2 ms.now i am trying to save these datas to my access database in a row by row format every 10 ms.So every 1 sec my access database should be updated with 100 rows of data.i am using the below code inside a timer ,but i can only manage to insert 20 rows.is there any possible ways to achieve this,or am i using a wrong approach.please help me out.

thanks

Dim datacomm As String
   Private Sub GetUpdates()
       Try
           datacomm = "insert into datatable1 ([date_], [time_], [data1], [data2], [data3], [data4], [data1_av], [data2_av],[data3_av],[data4_av],[filename]) values ('" _
                      & DateString & "',0,'" & Label138.Text & "','" & Label140.Text & "','" & Label142.Text & "','" & Label144.Text & "','" & Label134.Text & "','" & Label137.Text & _
                      "','" & Label133.Text & "','" & Label93.Text & "','" & My.Settings.excelfilename & "')"
           Dim cmd As New OleDbCommand(datacomm, myConn)
           cmd.ExecuteNonQuery()
       Catch ex As Exception
       End Try
   End Sub

推荐答案

您不会每10ms写入数据库。如果您要捕获10秒的数据,则只需将该数据缓存在内存中。捕获完成后,您可以解析该数据并将其写入数据库。



您正在做什么不会起作用而不是尽可能快地工作。



最重要的是,您将代码打开到SQL注入攻击,这可能会导致数据库完全丢失。使用参数化查询。 Google为vb.net参数化查询并开始阅读。
You don't write to the database every 10ms. If you're going to capture 10 seconds worth of data, you just cache that data in memory. When the capture is complete, then you can parse that data and write it to the database.

What you're doing isn't going to work and isn't going to work as fast as you want.

On top of that, you opened your code up to SQL Injection Attacks which can risk the complete loss of your database. Use parameterized queries. Google for "vb.net parameterized query" and start reading.


这篇关于每10毫秒更新一次数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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