如何通过单击显示按钮每次显示新数据,该按钮基于C#中Windows应用程序中maskedtextbox中输入的日期提取数据 [英] how to show new data everytime by clicking on show button which extract data based on date entered in maskedtextbox in windows application in c#

查看:152
本文介绍了如何通过单击显示按钮每次显示新数据,该按钮基于C#中Windows应用程序中maskedtextbox中输入的日期提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maskedtextbox,一个按钮和一个gridview.

每次我在maskedtextbox中输入日期以通过单击btnshow(button)
在gridview中显示数据时 它显示给我带有输入日期的数据,当我输入不同的日期时,它再次显示与输入的新日期相关的数据,还显示先前的数据...所以我不知道如何刷新gridview以仅显示与日期有关的新数据.
我的显示按钮代码如下;-

I have a maskedtextbox, a button and a gridview.

everytime i enter date in maskedtextbox to show data in gridview by clicking on btnshow(button)
it shows me data with the the entered date and again when i enter different date it shows me the data related to the new date entered but also the previous data...so i don''t know how to refresh the gridview to show only the new data related to date enetered.
My code for show button is as follows;-

private void BTN_SHOW_Click(object sender, EventArgs e)
        {
            
            SqlDataAdapter da = new SqlDataAdapter("select dicharge_date AS ''Discharge Date'',bed_id AS ''Room No'',level1 AS ''Floor No'',last_name AS ''Patient Name'',doctor_name AS ''Patient Dr. Name'',Discharge_Advice AS ''Dis Adv'',Discharge_Card AS ''Dis Card'',File_Check AS ''File Check'',Billing,Actual_Discharge AS ''Actual Discharge'',Time,reg_no,discharge_reason AS Remarks from NewDischargeTimes where dicharge_date=CONVERT(date, ''" + maskedtxbx_dischargedate.Text + "'', 103)", con);
            SqlCommandBuilder cmd = new SqlCommandBuilder(da);
            da.Fill(dtusers);
            dataGridView1.DataSource = dtusers;
            dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
            
        }

推荐答案

在添加带有datagridview.rows.clear()或datagridview.datatasource = null的行并清除代码之前,请清除datagridview.抱歉,我无法给出确切的答案,一个人应该可以从iphone接听我的电话,并且无法访问我的笔记
Clear your datagridview before you add rows with datagridview.rows.clear() or datagridview.datatasource = null and then the code to fill it up. Sorry i cant give the exact answer either one should work im answering from iphone and have no access to my notes


您好,


如果您的数据表dtusers在BTN_SHOW_Click之外声明,则可能是由于问题,该数据表将保留其旧值.


请添加dtusers.Clear();行.如下所示

Hi,


If your datatable dtusers is declared outside the BTN_SHOW_Click, issue might be due to, the datatabe is persisting its old values.


Please add the line dtusers.Clear(); like as follows

private void BTN_SHOW_Click(object sender, EventArgs e)
 {

dtusers.Clear();
SqlDataAdapter da = new SqlDataAdapter("select dicharge_date AS 'Discharge Date',bed_id AS 'Room No',level1 AS 'Floor No',last_name AS 'Patient Name',doctor_name AS 'Patient Dr. Name',Discharge_Advice AS 'Dis Adv',Discharge_Card AS 'Dis Card',File_Check AS 'File Check',Billing,Actual_Discharge AS 'Actual Discharge',Time,reg_no,discharge_reason AS Remarks from NewDischargeTimes where dicharge_date=CONVERT(date, '" + maskedtxbx_dischargedate.Text + "', 103)", con);
 SqlCommandBuilder cmd = new SqlCommandBuilder(da); 
da.Fill(dtusers); dataGridView1.DataSource = dtusers; 
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); 
}



如果有效的话请让我来!!!



Please let me if it worked!!


这篇关于如何通过单击显示按钮每次显示新数据,该按钮基于C#中Windows应用程序中maskedtextbox中输入的日期提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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