使用Timer来替代
在“button1”事件被触发后3000ms,如何使用timer替代“button2_Click”,来进行自动查询“Table_2”。请高手解答!以下为部分源码(在不对2张表进行关联或将2张表进行合并的前提下)
using System.Data;
...
using System.timers;
namespace 001
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string sqlstr = "select * from Table_1 where name='" + TextBox1.Text.Trim() + "'";
SqlConnection cn = new SqlConnection("Data Source=wang;Initial Catalog=InfoTables;Integrated Security=True");
SqlDataAdapter dap = new SqlDataAdapter(sqlstr, cn);
...
}
private void button2_Click(object sender, EventArgs e)
{
string sqlstr = "select * from Table_2 where size='" + TextBox2.Text.Trim() + "'";
SqlConnection cn = new SqlConnection("Data Source=wang;Initial Catalog=InfoTables;Integrated Security=True");
SqlDataAdapter dap = new SqlDataAdapter(sqlstr, cn);
...
}