How to delete the records from a sql table in VB.NET when a button is clicked.The records from the table in the database should be deleted.
Printable View
How to delete the records from a sql table in VB.NET when a button is clicked.The records from the table in the database should be deleted.
and in VB ..Code:SQL CODE:::: Stored procedure
CREATE PROCEDURE [dbo].[Del_From_Table]
@id int
DELETE
FROM [Table]
WHERE
[id] = @id
It's that easy ...Code:Dim sqlConn As New SqlConnection([ConnectionString])
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Try
sqlConn.Open()
With cmd
.Connection = sqlConn
.CommandType = CommandType.StoredProcedure
.CommandText = "Del_from_Table"
.Parameters.AddWithValue("@id", id)
.Connection = sqlConn
dr = .ExecuteReader()
End With
Catch ex As Exception
'Log an error here.....
End Try
Gremmy...
Okay that's not so difficult ..
Now you have a method ...Code:Dim sqlConn As New SqlConnection([ConnectionString])
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
Try
sqlConn.Open()
With cmd
.Connection = sqlConn
.CommandText = "DELETE FROM [Table] WHERE [id] = @id"
.Parameters.AddWithValue("@id", id)
.Connection = sqlConn
dr = .ExecuteReader()
End With
Catch ex As Exception
'Log an error here.....
End Try
Gremmy...