public partial class CountryMaster : System.Web.UI.Page
{
OleDbConnection conn = new OleDbConnection(@"Provider=MicroSoft.ACE.OLEDB.12.0;Data Souce=G:\WebDesign\WebGridView\WebGridView\Database\PracticeDataBase.accdb");
protected void Page_Load(object sender, EventArgs e)
{
}
int MaxVal()
{
int max = 0;
OleDbCommand comm = new OleDbCommand("Select max(CountryId) from CountryMaster", conn);
if (conn.State == ConnectionState.Closed)
conn.Open();
OleDbDataReader rd = comm.ExecuteReader();
if (rd.HasRows)
while (rd.Read())
int.TryParse(rd[0].ToString(), out max);
max++;
comm.Dispose();
conn.Close();
return max;
}
protected void btnsave_Click(object sender, EventArgs e)
{
OleDbCommand comm = new OleDbCommand("Insert into CountryMaster(CountryId,CountryName) Values(" + MaxVal() + ",'" + txtname.Text + "')", conn);
if (conn.State == ConnectionState.Closed)
conn.Open();
comm.ExecuteNonQuery();
comm.Dispose();
conn.Dispose();
}
}