13.07.2015 Views

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

ASP.NET 3.5: A Beginner's Guide - www.mustafaof.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12: ADO.<strong>NET</strong>: Hello Database 319protected void DropIt(object sender, EventArgs e){hookUp = new SqlConnection("Server=localhost\\SqlExpress;Database=VoteNow;" +"Integrated Security=True");strDelete = "DELETE FROM Supporters WHERE LastName=@LName";sqlCmd = new SqlCommand(strDelete, hookUp);sqlCmd.Parameters.Add("@LName", LName.Text);hookUp.Open();sqlCmd.ExecuteNonQuery();hookUp.Close();Label1.Text = LName.Text +" was deleted.";}}When you test the program, you will see that whatever name you enter in the input windowis repeated in a Label web control when you click the Delete Record button. If no suchrecord exists, it still shows the message because the label simply takes the entered text andechoes it in the label output. Figure 12-23 shows what you can expect to see when you testthe application.Figure 12-23 Interface for deleting database record

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!