Deleting SQL Server Data

If you have code on your ASP.NET pages that allows visitors to enter a record, or where you add records through code without their input, you will likely need to delete records from your pages. This technique shows you how to use a SQL Delete query to delete records from an SQL Server table.

When the page first loads, the following code will populate the DropDownList control:

Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)If Not IsPostBack ThenDim DBConn as SQLConnectionDim DBCommand As SQLDataAdapter Dim DSPageData as New DataSet
DBConn = New SQLConnection("server=localhost;" _& "Initial Catalog=TT;" _& "User Id=sa;" _"Password=yourpassword;") DBCommand = New SQLDataAdapter _ ("Select LastName + ‘ + FirstName "
& "as EmpName, EmpID " _& "From Employees " _& "Order By LastName, FirstName", DBConn)
DBCommand.Fill(DSPageData, _ "Employees")ddlEmps.DataSource = _DSPageData.Tables("Employees").DefaultViewddlEmps.DataBind()End IfEnd Sub

and this procedure fires when the Button control is clicked:

Sub SubmitBtn_Click(Sender As Object, E As EventArgs)


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: