Posted by: Sourav | June 1, 2015

Delete Data from SQL Server Using VB.Net


Delete using vb.net

Add another page

Rename the page of tab control as Delete

Add a label

 

Make the text “So who you want to delete”

Make the text larger

 

Add a button and make it’s name delete

 

Add this sub on your sqlcon.vb

 

Public Sub dataupdate(query As String)

       Try

           sqlcon.Open()

           sqlcommand = New SqlCommand(query, sqlcon)

           Dim change As Integer = sqlcommand.ExecuteNonQuery

 

 

 

 

 

           sqlcon.Close()

           If change = 0 Then

               MsgBox(“you haven’t found what you where looking for”)

           Else

               MsgBox(change & ” rows affected”)

 

           End If

 

 

       Catch ex As Exception

           MsgBox(ex.Message)

           If sqlcon.State = ConnectionState.Open Then

               sqlcon.Close()

           End If

       End Try

   End Sub

 

 

The code for delete button is

 

 

 

If TextBox7.Text <> “” Then

           If MsgBox(“Do you really want to delete ” & TextBox7.Text & ” ?”, MsgBoxStyle.YesNoCancel) = MsgBoxResult.Yes Then

               sqlcon.dataupdate(“Delete from test where Name = ‘” & TextBox7.Text & “‘”)

 

 

           End If

       End If

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: