Q.6)Write a program to perform insert,update and delete using
ListView control in asp.net.
Coding:
Imports System.Data.OleDb Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page Dim db_conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Users\ravip\Desktop\ravi prajapati\ASPNET\Data4.mdb'") Dim db_adepter As New OleDbDataAdapter("Select * from Table1", db_conn) Dim d_set As New DataSet Dim query As String Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click db_conn.Open() query = "Insert into Table1(Name,Address,PhoneNo) values (@name,@add,@phone)" Dim cmd As New OleDbCommand(query, db_conn) cmd.Parameters.AddWithValue("@name", TextBox1.Text) cmd.Parameters.AddWithValue("@add", TextBox2.Text) cmd.Parameters.AddWithValue("@phone", TextBox3.Text) cmd.ExecuteNonQuery() d_set.Clear() db_adepter.Fill(d_set, "Table1") db_conn.Close() ListView1.DataBind()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click db_conn.Open() query = "update Table1 set Name=@name,PhoneNo=@phone where Address=@add" Dim cmd As New OleDbCommand(query, db_conn) cmd.Parameters.AddWithValue("@name", TextBox1.Text) cmd.Parameters.AddWithValue("@phone", TextBox3.Text) cmd.Parameters.AddWithValue("@add", TextBox2.Text) cmd.ExecuteNonQuery() d_set.Clear() db_adepter.Fill(d_set, "Table1") db_conn.Close() ListView1.DataBind() Assignment=06
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button3.Click db_conn.Open() query = "delete from Table1 where name =@name" Dim cmd As New OleDbCommand(query, db_conn) cmd.Parameters.AddWithValue("@name", TextBox1.Text) cmd.ExecuteNonQuery() d_set.Clear() db_adepter.Fill(d_set, "Table1") db_conn.Close() ListView1.DataBind() End Sub End Class