如何在窗体中的数据库中插入数据后刷新Form [英] How to refresh Form after insert data in database in window forms

查看:61
本文介绍了如何在窗体中的数据库中插入数据后刷新Form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个问题。我想在添加,更新和删除数据后刷新表单。

在我的情况下,我有一个文本框,其中id是自动增量我希望当我插入数据时ID应该在插入后更改我使用

表格加载上的此代码

Hi,
I have a one problem. I want to refresh form after add,update and delete data.
In my Case i have a textbox where id is auto increment i want when i insert data Id should be changed after insertion I use
this code on Form Load

OleDbCommand cmd1 = new OleDbCommand("select max(patientid) as pi from patient", con);    
            dr = cmd1.ExecuteReader();
            dr.Read();
            if (dr["pi"].ToString() != "")
            {
                temp = int.Parse(dr["pi"].ToString()) + 1;
            }
            else
            {
                temp = 1;
            }
           
           
            this.txtpatientid.Text = temp.ToString();
            dr.Close();





Id在表格关闭后递增。关闭后我不希望表单重新加载

我希望textbox id在没有关闭表单的情况下递增。



Id is increment after form close. I dont want form reload after close
I want textbox id shoul be increment without close the form .

推荐答案

写这个页面加载的最佳方式函数中的代码和插入后的调用或者你想要的地方... exa ..

best way write this page load code in function and call after insert or where u want...exa..
private void MyAutoId()
{
OleDbCommand cmd1 = new OleDbCommand("select max(patientid) as pi from patient", con);
dr = cmd1.ExecuteReader();
dr.Read();
if (dr["pi"].ToString() != "")
{
temp = int.Parse(dr["pi"].ToString()) + 1;
}
else
{
temp = 1;
}


this.txtpatientid.Text = temp.ToString();
dr.Close();

}





并在表单加载或你想要的地方调用它..



and call it in form load or where u want..


这篇关于如何在窗体中的数据库中插入数据后刷新Form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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