Dataadapter DeleteCommand - Sql Server
SqlDataAdapter, as an integral component of the ADO.NET Data Provider, plays a vital role in updating a database with data modifications made on a DataSet object. This functionality is facilitated through the InsertCommand, UpdateCommand, and DeleteCommand properties of the SqlDataAdapter object.
To illustrate the usage of the SqlDataAdapter object and its UpdateCommand properties for updating a SQL Server database, consider the following code samples:
Full Source VB.NET
Imports System.Data.SqlClient
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 adapter As New SqlDataAdapter
Dim sql As String
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
connection = New SqlConnection(connetionString)
sql = "delete product where Product_name ='Product7'"
Try
connection.Open()
adapter.DeleteCommand = connection.CreateCommand
adapter.DeleteCommand.CommandText = sql
adapter.DeleteCommand.ExecuteNonQuery()
MsgBox("Row(s) deleted !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
Ensure that you replace "YourConnectionString", "YourTable", and the column names in the update query with the appropriate values for your specific scenario.
Related Topics
- Dataadapter with dataset - sql sever
- Dataadapter with dataset - OLEDB Data Source
- Dataadapter SelectCommand - Sql Server
- Dataadapter SelectCommand - OLEDB Data Source
- Dataadapter InsertCommand - Sql Server
- Dataadapter InsertCommand - OLEDB Data Source
- Dataadapter UpdateCommand - Sql Server
- Dataadapter UpdateCommand - OLEDB Data Source
- Dataadapter DeleteCommand - OLEDB Data Source
- Dataadapter with CommandBuilder - Sql Server
- Dataadapter with CommandBuilder - OLEDB
- Dataadapter with DataGridView - Sql Server
- Dataadapter with DataGridView - OLEDB