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

 

Example 35 SqlFormDeleteDemo.aspx

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

<Script Runat="Server">

Sub Button_Click( s As Object, e As EventArgs )

Dim conNorthwind As SqlConnection

Dim strDelete As String

Dim cmdDelete As SqlCommand

Dim intCountRecord As Integer

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

strDelete = "Delete Books Where Author=@AuthName"

cmdDelete = New SqlCommand( strDelete, conNorthwind )

cmdDelete.Parameters.Add( "@AuthName", txtAuthName.Text )

conNorthwind. Open ()

intCountRecord = cmdDelete.ExecuteNonQuery()

conNorthwind. Close ()

lblMessage. Text = intCountRecord & " records deleted!"

End Sub

</Script>

<html>

<head><title>SqlFormDelete.aspx</title></head>

<body>

<form Runat="Server">

<h2>Delete Books</h2>

<b>Author's Name:</b>

<br>

<asp:TextBox

ID="txtAuthName"

Runat="Server" />

<p>

<asp:Button

Text="Delete"

OnClick="Button_Click"

Runat="Server" />

<p>

<asp:Label

ID="lblMessage" Runat="Server" />

</form>

</body>

</html>

 
 

The output of this example is shown as below:

The above example contains one TextBox control named txtAuthName. When you click the Delete button, the Button Click subroutine is executed, and the book with the speci­fied author is deleted from the Authors database table. A count of the number of records deleted is retrieved from the ExecuteNonQuery () method and assigned to a Label control named lblMessage.

The MS Access version of above example is shown as:

Example 36 OleDBFormDeleteDemo.aspx

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

<Script Runat="Server">

Sub Button_Click (s As Object, e As EventArgs)

Dim conBooks As OleDbConnection

Dim strDelete As String

Dim cmdDelete As OleDbCommand

Dim intCountRecord As Integer

 

conBooks= New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=c:\Books.mdb")

strDelete = "Delete from Books Where Author=@AuthName"

cmdDelete = New OleDbCommand( strDelete, conBooks )

cmdDelete.Parameters.Add( "@AuthName", txtAuthName.Text )

conBooks. Open ()

intCountRecord = cmdDelete.ExecuteNonQuery()

conBooks. Close ()

lblMessage. Text = intCountRecord & " records deleted!"

End Sub

</Script>

<html>

<body>

<form Runat="Server">

 

<h3>Delete Books</h3>

<b>Author's Name:</b>

<br>

<asp:TextBox

ID="txtAuthName"

Runat="Server" />

<p>

<asp:Button

Text="Delete"

OnClick="Button_Click" Runat="Server" />

<p>

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

</form>

</body>

</html>

 

The output of above example is as shown below:-

The above example contains one TextBox control named txtAuthName. When you click the Delete button, the Button Click subroutine is executed, and the book with the speci­fied author is deleted from the Authors database table. A count of the number of records deleted is retrieved from the ExecuteNonQuery () method and assigned to a Label control named lblMessage.

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