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
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Makeup Artist Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

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

ASP.NET Tutorial - ADO.NET

                                                                                                                Page 9 of 14
 

In the above example there are two TextBox controls named txtbookName and txtAuthor. When the Add Books! Button, are clicked the Button Click subroutine is executed, and the values entered into the two TextBox controls are inserted into the Books table of MS Access database which is located at c:\Books.mdb.

Updating Database Records

To update the database record in the table the UPDATE command is used as: -

Suppose you want to update a table Book in which you want to Update the name of the Author from “John” to “David”. The code used would be like: -

Update books

Set Author=’David’

Where Author=’John’

To use UPDATE COMMAND follow these steps: -

1.Create and open a database connection.

2.Create a database command that represents the SQL Update statement to execute.

3.Execute the command with the ExecuteNonQuery () method.

The following example shows how the books are updated.

Author Updated in the Table Books!

The output of this example is shown below: -

The first statement in the above example imports the necessary namespace for working with the SQL ADO.NET classes.

Next, a database connection is initialized with the correct connec­tion string for the local server. In the statement that follows, passing a SQL Update command and SqlConnection to the constructor for the class creates an instance of the SqlCommand class.

The SQL Update command is executed when the ExecuteNonQuery () method of the SqlCommand class is called. At this point, the Update statement is transmitted to SQL Server and executed.

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

The output of this example is as shown below:-

The first statement in the above example imports the necessary namespace for working with the OleDb ADO.NET classes. Next, a database connection is initialized with the correct connec­tion string for the local server. In the statement that follows, passing a SQL Update command and OleDbConnection to the constructor for the class creates an instance of the OleDbCommand class.

The SQL Update command is executed when the ExecuteNonQuery () method of the OleDbCommand class is called. At this point, the Update statement is transmitted to MS Access and executed.

 

       

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