public void getdata() { txteno.Text = ds.Tables[0].Rows[rno][0].ToString(); txtenme.Text = ds.Tables[0].Rows[rno][1].ToString(); txtjob.Text = ds.Tables[0].Rows[rno][2].ToString(); txtloc.Text = ds.Tables[0].Rows[rno][3].ToString(); txtpno.Text = ds.Tables[0].Rows[rno][4].ToString(); } protected void Page_Load(object sender, EventArgs e) { string scon = ConfigurationManager.ConnectionStrings["scn"].ConnectionString; cn = new SqlConnection(scon); da = new SqlDataAdapter("select * from emphalf", cn); ds = new DataSet(); da.Fill(ds, "emphalf"); getdata(); } protected void btnprev_Click(object sender, EventArgs e) { if (rno > 0) { rno -= 1; if (ds.Tables[0].Rows[rno].RowState == DataRowState.Deleted) { // DataRow dr = (DataRow)ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]; Response.Write("deleted row data cannot be accessed"); return; } getdata(); } else Response.Write("first record"); } protected void btnxt_Click(object sender, EventArgs e) { if (rno < ds.Tables[0].Rows.Count - 1) { rno += 1; if (ds.Tables[0].Rows[rno].RowState == DataRowState.Deleted) { Response.Write("deleted row data cannot be accessed"); return; } getdata(); } else Response.Write("last record"); } protected void btninsert_Click(object sender, EventArgs e) { DataRow dr = ds.Tables[0].NewRow(); dr[0] = txteno.Text; dr[1] = txtenme.Text; dr[2] = txtjob.Text; dr[3] = txtloc.Text; dr[4] = txtpno.Text; ds.Tables[0].Rows.Add(dr); rno = ds.Tables[0].Rows.Count - 1; Response.Write("data row is added"); getdata(); } protected void btnupdate_Click(object sender, EventArgs e) { ds.Tables[0].Rows[rno][1] = txtenme.Text; ds.Tables[0].Rows[rno][2] = txtjob.Text; ds.Tables[0].Rows[rno][3] = txtloc.Text; ds.Tables[0].Rows[rno][4] = txtpno.Text; Response.Write("data row is updated"); getdata(); } protected void btndelete_Click(object sender, EventArgs e) { ds.Tables[0].Rows[rno].Delete(); Response.Write("data row is deleted"); getdata(); } protected void btnsave_Click(object sender, EventArgs e) { cb = new SqlCommandBuilder(da); da.Update(ds, "emphalf"); Response.Write("data is saved to database"); getdata(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)