Wednesday, 7 March 2012

Delete query opeartion.

Now we have seen how to insert data in database.Now will see how to delete data from database.
consider following entries are there in database.


Here we will perform delete opeartion using roll no. attribute.Now modify your .aspx page by adding two control textbox and delete button as shown below:



Now open .aspx.vb page by double clicking delete button now add following code to .aspx.vb page.
Code to be written in button click event of delete button:
 Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("a").ToString())
        Dim sqlqry As String = "delete from Table1 where Rollno=' " & txt4.Text & " ' "
        Dim cmd As SqlCommand
        Try
            connection.Open()
            cmd = New SqlCommand(sqlqry, connection)
            cmd.ExecuteNonQuery()
        Catch ex As Exception
            lblmsg.Text = ex.Message
        Finally
            connection.Close()
        End Try








In above code "a" is your connection string.txt4 is ID of your control which takes roll no of  student whose entry you want to delete..
        
Now save and run your website:Enter roll no of which entry you want to delete.

Now view whether this entry is deleted or not.Go to database explorer right click on table and click show table data.Now you can see Suresh's entry is deleted from table as shown below:



No comments:

Post a Comment