本文介绍了如何从winform C#每1小时后访问或执行数据库操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

i有winform c#visual studio 2012

i需要你的帮助

其实我想执行数据库操作(每1小时后从我的winform中选择,更新,删除或插入。在1小时之前,数据库中应该没有任何动作。



让我采取一种方案。

实际上在我的winform中,我执行select查询和从DB(数据库)获取的数据保存在我的数据表中。

通过datagridview我允许用户执行一些修改,如添加新记录,删除等..

现在当用户点击保存按钮时,所有这些修改首先保存在我的数据表中,然后仅在1小时后在我的数据库中更新。下一个选择的数据库查询也应该在1小时后出现



我被卡住了,我怎么能这样做?



我尝试过:



public string strcon =server = xxxx; database = xxx; username = xxx ; password = xx;;

MySqlConnection conn = new MySqlConnection();

DataTable dt = new DataTable();

conn.ConnectionString = strcon;

if(conn.State == ConnectionState.Closed || conn.State == ConnectionState.Broken)

conn.Open();

MySqlCommand cmd = new MySqlCommand(select * from enugro_service_requests_info,conn);



MySqlDataReader rd = cmd.ExecuteReader();

dt.Load(rd);

this.dataGridView1.DataSource = dt;

解决方案

hi all,
i have winform c# visual studio 2012
i need your help
in fact, i would like to perform database operation (select,update,delete or insert) from my winform after each 1 hour. Before 1 hour there should have no action in the database.

let me take one scenario.
actually in my winform, i performed select query and the data fetched from the DB(database) are saved in my datatable.
through a datagridview i allow user to perform some modifications,like add new record, delete etc..
now when user click on save button, all these modifications are saved first in my datatable and then updated in my DB only after 1 hour. And the next select query towards database should come also after 1 hour

I'm stuck,How can i do it?

What I have tried:

public string strcon = "server=x.x.x.x; database=xxx; username=xxx; password=xx;";
MySqlConnection conn = new MySqlConnection();
DataTable dt = new DataTable();
conn.ConnectionString = strcon;
if (conn.State==ConnectionState.Closed || conn.State== ConnectionState.Broken)
conn.Open();
MySqlCommand cmd = new MySqlCommand("select * from enugro_service_requests_info", conn);

MySqlDataReader rd = cmd.ExecuteReader();
dt.Load(rd);
this.dataGridView1.DataSource =dt;

解决方案


这篇关于如何从winform C#每1小时后访问或执行数据库操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:20