0% found this document useful (0 votes)
12 views

DNET 9

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

DNET 9

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Date:

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 = "";
}

protected void Button2_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand comm = new SqlCommand("update Table2 set NAME='" +
TextBox2.Text + "', EMAIL = '"+TextBox3.Text +"',Contact = '"+TextBox4.Text +"' where
ID='"+TextBox1.Text+"' ", con);

comm.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script",
"alert('Successfully Updated');", true);

LoadRecord();
ClearData(); }

protected void Button3_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand comm = new SqlCommand("delete table2 where ID = '" +
TextBox1.Text + "' ", con);

comm.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script",
"alert('Successfully Deleted');", true);

LoadRecord();
ClearData();

}
}
}

.NET Technologies Lab (01CE1602) 25


Output:
1) INSERT:

2) Update:

.NET Technologies Lab (01CE1602) 26


3) Delete:

.NET Technologies Lab (01CE1602) 27

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy