ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
ASP Dot Net Tutorial - Index
ASP Dot Net Tutorial - Microsofts ASP.NET
ASP Dot Net Tutorial - Begining Web Forms
ASP Dot Net Tutorial - User Controls
ASP Dot Net Tutorial - ADO .NET
ASP Dot Net Tutorial - DataBinding to WebControls
ASP Dot Net Tutorial - DataList Controls
ASP Dot Net Tutorial - DataGrid Control
ASP Dot Net Tutorial - Advance Practical Examples on DataGrid
ASP Dot Net Tutorial - Working with DataSets
ASP Dot Net Tutorial - Working with XML
ASP Dot Net Tutorial - Forms Based Authentication
ASP Dot Net Tutorial - Windows Based Authentication
     

 
Online Personal Trainer Certification
Test Search by Job Title
Find a Personal Trainer
Job Resources
Free Self Tests and Quizzes
Find a Lawyer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Six Sigma Green Belt Certification
Lean Management Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
SEO Certification
Online Photography Course & Certification
Online Business Writing Course & Certification
Baby Sitting Course & Certification
Time Manangement Certification
Health Club Management Certification
Selling Skills Certification
Business Analysis Course
Green Living Course  free!
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > ASP.NET Tutorial > ADO.NET
 

ASP.NET Tutorial - ADO.NET

                                                                                                            Page 10 of 14
 

Parametric UPDATE

Practically Parametric UPDATE is used in the form of a web i.e. the parameters are passed from outside.

One difference between the SQL Update and Insert commands is that the SQL Update command affects more than one record at a time. When you execute an Update command, it changes every record that satisfies the command where clause.

You can determine the number of records affected by an Update command within an ASP.NET page by holding the value returned by the ExecuteNonQuery () method. The following example demonstrates it: -

Example 31 SqlDbParameterUpdate.aspx

<%@ Import Namespace="System.Data.SqlClient" %>

<Script Runat="Server">

Sub Button_Click (s As Object, e As EventArgs)

Dim conNorthwind As SqlConnection

Dim strUpdate As String

Dim cmdUpdate As SqlCommand

Dim intRecordCount As Integer

conNorthwind = New SqlConnection( "Server=localhost;UID=sa;PWD=secret;database=Northwind" )

strUpdate = "Update Books Set Author=@author_name Where bookName=@book_name"

cmdUpdate = New SqlCommand( strUpdate, conNorthwind )

cmdUpdate.Parameters.Add( "@book_name", txtBookName.Text )

cmdUpdate.Parameters.Add( "@author_name", txtAuthorName.Text )

conNorthwind. Open ()

intRecordCount = cmdUpdate.ExecuteNonQuery()

conNorthwind. Close ()

lblAuthor. Text = intRecordCount & " records updated!"

End Sub

</Script>

<html>

<body>

<form Runat="Server">

<h3>Update Book's Name</h3>

<b>Book Name</b>

<br>

<asp:TextBox

ID="txtBookName"

Runat="Server" />

<p>

<br>

<b>Author's Name</b>

<br>

<asp:TextBox

ID="txtAuthorName"

Runat="Server" />

<p>

<asp:Button Text="Update Author" OnClick="Button_Click" Runat="Server" />

<p>

<asp:Label ID="lblAuthor" Runat="Server" />

</form>

</body>

</html>

 

The output of this example is as shown below:

The above example has two TextBox controls: one in a Book’s name and the other in Author’s Name. When you click the Update Author! Button, the Button Click subroutine is executed, and the phone number for the real author is updated.

Finally, the number of records updated is retrieved from the ExecuteNonQuery () method of the SqlCommand class. This result is assigned to a Label control lblAuthor.

The code in above example works only with Microsoft SQL Server (version 7.0 and higher). If you want to update a record in a Microsoft Access database table, you need to use the ADO.NET classes from the System.Data.OleDb namespaces rather than the System.Data.SqlClient namespace as shown below: -

The above example has two TextBox controls: one in a Book’s name and the other in Author’s Name. When you click the Update Author! Button, the Button Click subroutine is executed, and the phone number for the real author is updated.

Finally, the number of records updated is retrieved from the ExecuteNonQuery () method of the SqlCommand class. This result is assigned to a Label control lblAuthor.

The code in above example works only with Microsoft SQL Server (version 7.0 and higher). If you want to update a record in a Microsoft Access database table, you need to use the ADO.NET classes from the System.Data.OleDb namespaces rather than the System.Data.SqlClient namespace as shown below: -

       


 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2006. All Rights Reserved.