DNET 9
DNET 9
02/04/2023
Create web application that performs CRUD operation using ADO.Net
Ex: 9
Enrollment No: 92100103241 Name: Umiya Rathod Class & Batch: 6TC4-B
WebForm1.aspx.cs:
Source Code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
namespace LAB9
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
SqlConnection con = new SqlConnection("Data Source = umiya\\sqlexpress; Initial
Catalog = lab8; Integrated Security = True");
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand comm = new SqlCommand("INSERT INTO Table2 VALUES('" +
TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "')",
con);
comm.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script",
"alert('Successfully Inserted');", true);
LoadRecord();
ClearData(); }
void LoadRecord() {
SqlCommand comm = new SqlCommand("select * from table2", con);
SqlDataAdapter d = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
.NET Technologies Lab (01CE1602) 24
d.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind(); }
void ClearData() {
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
}
comm.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script",
"alert('Successfully Updated');", true);
LoadRecord();
ClearData(); }
comm.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script",
"alert('Successfully Deleted');", true);
LoadRecord();
ClearData();
}
}
}
2) Update: