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 > Working with DataSets
 

ASP.NET Tutorial - Working with DataSets

                                                                                                                 Page 4 of 5
 

DataTable Properties

There are four properties of a Da`taTable:

CaseSensitive

Determines whether the comparisons after searching, sorting, or filter­ing records are case sensitive (the default value is False)

MinimumCapacity

Specifies the initial number of rows that the DataTable accepts (the default value is 25)

PrimaryKey

Specifies the array of columns to be used as the primary keys for the DataTable

TableName

Specifies the name of the DataTable Creating

Creating Datatables by using Programs

Typically, a DataTable can be created from an existing database table. However, programs can also be used, for creating a DataTable and adding it, to a DataSet.

A DataTable has a collection of rows and arrows represented by the Rows property and Columns property. A DataTable can be build by programming­, consisting of records by adding DataColumns to the columns collection and DataRows to the rows collection.

In the following example, a new DataTable is created with four columns: ProductID,ProductName, ProductCategory, and ProductPrice. Next, the two rows are added to the DataTable. The contents of the DataTable are then displayed.

 

Example 54 ExpertCreateDataTable.aspx

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

<%

Dim dtblCart As DataTable

Dim dcolColumn As DataColumn

Dim drowItem As DataRow

 

' Creating DataTable

dtblCart = New DataTable( "Cart" )

 

' Creating Columns

dcolColumn = New DataColumn( "ProductID", GetType( Int32 ) )

dtblCart.Columns.Add( dcolColumn )

dcolColumn = New DataColumn( "ProductName", GetType( String ) )

dtblCart.Columns.Add( dcolColumn )

dcolColumn = New DataColumn( "ProductCategory", GetType( String ) )

dtblCart.Columns.Add( dcolColumn )

dcolColumn = New DataColumn( "ProductPrice", GetType( Decimal ) )

dtblCart.Columns.Add( dcolColumn )

 ' Adding Rows

drowItem = dtblCart.NewRow()

drowItem( "ProductID" ) = 12

drowItem( "ProductName" ) = "Anchor Steam"

drowItem( "ProductCategory" ) = "Beer"

drowItem( "ProductPrice" ) = 7.90

dtblCart.Rows.Add( drowItem )

 drowItem = dtblCart.NewRow()

drowItem( "ProductID" ) = 13

drowItem( "ProductName" ) = "Samuel Adams"

drowItem( "ProductCategory" ) = "Beer"

drowItem( "ProductPrice" ) = 8.67

dtblCart.Rows.Add( drowItem )

 ' Displaying DataTable

For each drowItem in dtblCart.Rows

For each dcolColumn in dtblCart.Columns

Response.Write( drowItem( dcolColumn ) )

Next

Next

%>

s
 


In the above example, an instance of the DataTable class-named dtblCart-is created. Further, four columns are added to the DataTable by adding DataColumns to the DataTable's columns collection. Each column is created with a name and data type.

Next, two rows are added to the DataTable. By using the DataTable's NewRow( ) method, a new row is created with the correct column schema for the DataTable. After a value has been assigned to each column, the row is added to the DataTable's rows collection.

Finally, the contents of the DataTable are displayed by looping through the rows and columns collections of the DataTable. The value of each column for each row is displayed.

       

 

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