Insert Update Save Delete using ListView

Satyapriyanayak
Posted by Satyapriyanayak under VB.NET category on | Points: 40 | Views : 938
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim i As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlDataAdapter1.Fill(DataSet11)
bind()
End Sub
Sub bind()
For i = 0 To DataSet11.Tables(0).Rows.Count - 1
ListView1.Items.Add(DataSet11.Tables(0).Rows(i).Item(0))
ListView1.Items(i).SubItems.Add(DataSet11.Tables(0).Rows(i).Item(1))
ListView1.Items(i).SubItems.Add(DataSet11.Tables(0).Rows(i).Item(2))
ListView1.Items(i).SubItems.Add(DataSet11.Tables(0).Rows(i).Item(3))
ListView1.Items(i).SubItems.Add(DataSet11.Tables(0).Rows(i).Item(4))
Next
End Sub

Private Sub btnaddnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddnew.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
Me.BindingContext(DataSet11, "student").AddNew()
TextBox1.Focus()
End Sub

Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Me.BindingContext(DataSet11, "student").EndCurrentEdit()
SqlDataAdapter1.Update(DataSet11, "student")
End Sub

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
Me.BindingContext(DataSet11, "student").RemoveAt(Me.BindingContext(DataSet11, "student").Position)
SqlDataAdapter1.Update(DataSet11, "student")
End Sub

Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
Me.Close()
End Sub

Private Sub btnfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnfirst.Click
Me.BindingContext(DataSet11, "student").Position = 0
End Sub

Private Sub btnprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprevious.Click
Me.BindingContext(DataSet11, "student").Position = Me.BindingContext(DataSet11, "student").Position - 1
End Sub

Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
Me.BindingContext(DataSet11, "student").Position = Me.BindingContext(DataSet11, "student").Position + 1
End Sub

Private Sub btnlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlast.Click
Me.BindingContext(DataSet11, "student").Position = Me.BindingContext(DataSet11, "student").Count - 1
End Sub
End Class

Comments or Responses

Login to post response