Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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 is increment after form close. I dont want form reload after close
I want textbox id shoul be increment without close the form .
Posted
Updated 12-Mar-13 0:15am
v2

1 solution

best way write this page load code in function and call after insert or where u want...exa..
C#
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..
 
Share this answer
 
Comments
veenusethi 12-Mar-13 6:34am    
Thanks and I already done this way before seeing it
Pallavi Waikar 12-Mar-13 6:39am    
good :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900