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..