读取表中的行 [英] Reading rows of a table

查看:50
本文介绍了读取表中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一些代码,它将每10秒读取一次名为table1的表的所有行....任何人都知道如何做到最好...感谢

Hi I am looking for some code that will read all the rows of a table called table1 every 10 second....anyone knows how to do it best...thanks

推荐答案

假定您的意思是一个SQL表,然后将普通代码放在Timer事件中.
尝试:
Assuming that you mean an SQL table, then just put the normal code in a Timer event.
Try:
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT * FROM MyTable", con))
        {
        using (SqlDataReader reader = com.ExecuteReader())
            {
            while (reader.Read())
                {
                ...
                }
            }
        }
    }

,但这可能是一个非常糟糕的主意-您将导致大量不必要的流量,并为SQL Server工作.您想实现什么,您认为这将是一个好主意?可能有更好的方法.

But it is probably a very bad idea to do it - you will cause enormous amounts of unnecessary traffic, and work for the SQL server. What are you trying to achieve, that you think this will be a good idea? There may be a better way.


使用计时器..

Use timer..

private void timer1_Tick(object sender, EventArgs e)
        {
        // Your data retrieval code

          }


这篇关于读取表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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