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
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 7 of 14

The above page contains two TextBox controls named tbFirstname and tbLastname. When you enter values into the two Textbox controls and click Submit, the Button Click subroutine is executed. hype

The Button Click subroutine creates an instance of the OleDbCommand class with a parame­tric Select statement. Two instances of the OleDbParameter class are created and added to the Parameters collection of the OleDbCommand class. For example, the @firstname para­meter is created and added with the following statement:

This statement creates a new OleDbParameter named @firstname and adds it to the Parameters collection of the OleDbCommand class. Passing its name and value creates the parameter. In this case, the value of the parameter is the value of the tbFirstname TextBox control.

Inserting Values in a Table [INSERT Command]

 We can use INSERT command for inserting the new records in the table. The syntax of this command is: -

If we try to write this command for our employees’ table, we will write it as:

The important steps needed to execute the INSERT command is: -

1. Create and open a database connection.

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

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

The following example demonstrates the INSERT command

The output of this example is shown below:

The first line in the above example imports the necessary namespaces to use the OleDb classes.

Next, a connection to an OleDb database is initialized.

Then, a variable named strInsert that has a SQL Insert statement as its value is created .The statement inserts a new record into a table named Books in database.

In the statement that follows, an instance of the OleDbCommand class is created. This class is initialized with two parameters: the command to execute and the connection to use for executing the command.

Finally, the command is executed by calling the ExecuteNonQuery () method of the OleDbCommand class. This method sends the SQL command to the database server, and the database server executes the command.

Here we have used ExecuteNonQuery () rather than ExecuteReader () to execute the command. ExecuteNonQuery () method is used because you are not returning any records from the database.

Parametric Insert

Practically Parametric Insert is used in the form of a web i.e. the parameters are passed from outside. The following example demonstrates it.




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