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.

316<strong>ASP</strong>.<strong>NET</strong> <strong>3.5</strong>: A Beginner’s <strong>Guide</strong>protected void UpdateData(object sender, EventArgs e){hookUp = new SqlConnection("Server=localhost\\SqlExpress;Database=VoteNow;" +"Integrated Security=True");strUpdate = "UPDATE Supporters SET LastName=@NName WHERE (LastName=@LName)";sqlCmd = new SqlCommand(strUpdate, hookUp);sqlCmd.Parameters.Add("@LName", LName.Text);sqlCmd.Parameters.Add("@NName", NewName.Text);hookUp.Open();sqlCmd.ExecuteNonQuery();hookUp.Close();Label1.Text = "Your Record is updated.";}}Once you have <strong>com</strong>pleted the application, test it. Figure 12-21 shows how it lookswhen you run it using Visual Studio 2008. The sample Supporters table has one personwith a last name of Jones, and it should change it to Smith.Figure 12-21 Updating a field

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

Saved successfully!

Ooh no, something went wrong!