How to delete rows in DataView
The DataView provides different views of the data stored in a DataTable. DataView can be used to sort, filter, and search data in a DataTable , additionally we can add new rows and modify the content in a DataTable. Also we can delete the data from the DataView . The following source code shows how to delete the data from DataView.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
Dim connection As SqlConnection
Dim command As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim dv As DataView
Dim sql As String
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
sql = "Select * from product"
connection = New SqlConnection(connetionString)
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds, "Delete Row")
dv = New DataView(ds.Tables(0), "", "Product_ID", DataViewRowState.CurrentRows)
DataGridView1.DataSource = dv
Catch ex As Exception