private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
SqlConnection drcon = new SqlConnection("Data Source=laptop-cl08flf2;Initial Catalog=hospital;Integrated Security=SSPI");
drcon.Open();
string str = "select patient_info.name,age from patient_info,doctor_info,pd_info where patient_info.number = pd_info.number and doctor_info.workid = '"+textBox1.Text+"' and doctor_info.category = pd_info.category and doctor_info.category = patient_info.category and doctor_info.expe = pd_info.expe and doctor_info.expe = patient_info.expe and pd_info.number in(select pd_info.number from pd_info where pd_info.number in(select pd_info.number from pd_info where differ = 'true' and going = 'no') )";
SqlCommand mycon = new SqlCommand(str, drcon);
mycon.ExecuteNonQuery();
SqlDataAdapter ada = new SqlDataAdapter(str, drcon);
DataSet pd = new DataSet();
ada.Fill(pd, str);
this.dataGridView1.DataSource = pd.Tables["pd_info"];
drcon.Close();
}
private void timer1_Tick(object sender, EventArgs e)
{
SqlConnection drcon = new SqlConnection("Data Source=laptop-cl08flf2;Initial Catalog=hospital;Integrated Security=SSPI");
drcon.Open();
string selstr = "select * from pd_info";
SqlCommand mycon = new SqlCommand(selstr, drcon);
mycon.ExecuteNonQuery();
SqlDataAdapter myada = new SqlDataAdapter("select * from pd_info",drcon);
DataSet pd = new DataSet();
myada.Fill(pd, "pd_info");
this.dataGridView1.DataSource = pd.Tables["pd_info"];
drcon.Close();
}
第一个是datagridview的代码
第二个是timer的
我是想datagridview里显示我查找后的结果,这个结果的显示是要在填写工号后自动显示(如图)然后timer里设置让这个datagridview定时查找并显示,不知道我这样写对不对,我刚开始学c#,求大佬求教,能帮我改代码更好
图是我的界面设计,datagridview里显示name和age两列
