ADO.NET Assignment Help

Assignment Help: >> ASP.Net Programming >> ADO.NET

ADO.NET:

ADO.Net gives a bridge between the front end controls and the back end database. The ADO.Net objects encapsulate all the data access operations and the controls communicate with these objects to display data, thus hiding the details of group of data.

The subsequent figure illustrates the ADO.Net objects at a glance:

 

767_ado.net.png

The DataSet Class:

The data set shows a subset of the database. It does not have a continuous connection to the database. To update the database a reconnection is needed. The DataSet has DataTable objects and DataRelation objects. The DataRelation objects show the relationship between two tables.

subsequent table shows some important properties of the DataSet class:

Properties

Description

CaseSensitive

Specify whether string comparisons within the data tables are case-sensitive.

Container

Gets the container for the component.

DataSetName

Gets or sets the name of the present data set.

DefaultViewManager

Gives a view of data in the data set.

DesignMode

Denotes whether the component is presently in design mode.

EnforceConstraints

Denotes whether constraint rules are followed when attempting any update operation.

Events

Gets the list of event handlers that are attached to that component.

ExtendedProperties

Gets the collection of customized user information related with the DataSet.

HasErrors

Denotes if there are any errors.

IsInitialized

Denotes whether the DataSet is initialized.

Locale

Gets or sets the locale information used to check strings within the table.

Namespace

Sets or gets the namespace of the DataSet.

Prefix

Sets or gets an XML prefix that aliases the namespace of the DataSet.

Relations

Gives the collection of DataRelation objects.

Tables

Gives the collection of DataTable objects.

subsequent table illustrates some important methods of the DataSet class:

Methods

Description

AcceptChanges

Accepts all modification made since the DataSet was loaded or this method was called.

BeginInit

Begins the initialization of the DataSet. The initialization happens at run time.

Clear

Clears data.

Clone

Copies the structure of the DataSet, adding all DataTable schemas, relations, and constraints. Does not copy any data.

Copy

Copies both the structure and data.

CreateDataReader()

Gives a DataTableReader with one result set per DataTable, in the same sequence as the tables seems in the Tables collection.

CreateDataReader(DataTable[])

Gives a DataTableReader with one result set per DataTable.

EndInit

Ends the initialization of the data set.

Equals(Object)

Calculates whether the specified Object is equal to the present Object.

Finalize

Free resources and operate other cleanups.

GetChanges

Gives a copy of the DataSet with all modification made since it was loaded or the AcceptChanges method was called.

GetChanges(DataRowState)

Gets a copy of DataSet with all modification made since it was loaded or the AcceptChanges method was known, filtered by DataRowState.

GetDataSetSchema

Gets a copy of XmlSchemaSet for the DataSet.

GetObjectData

Populates a serialization data object with the data required to serialize the DataSet.

GetType

Gets the kind of the present instance.

GetXML

Gives the XML representation of the data.

GetXMLSchema

Gives the XSD scheme for the XML representation of the data.

HasChanges()

Gets a value representing whether the DataSet has changes, including new, deleted, or modified rows.

HasChanges(DataRowState)

Gets a value representing whether the DataSet has changes, including new, deleted, or modified rows, filtered by DataRowState.

IsBinarySerialized

Inspects the format of the serialized demonstration of the DataSet.

Load(IDataReader, LoadOption, DataTable[])

Fills a DataSet with values from a data source with the supplied IDataReader, using an array of DataTable instances to provide the schema and namespace information.

Load(IDataReader, LoadOption, String[])

Fills a DataSet with values from a data source using the supplied IDataReader, using an array of strings to provide the names for the tables within the DataSet.

Merge()

Merges the data with data from one more DataSet. This technique has different overloaded forms.

ReadXML()

Reads an XML schema and data into the DataSet. This technique has different overloaded forms.

ReadXMLSchema(0

Reads an XML schema into the DataSet. This function has different overloaded forms.

RejectChanges

Rolls back all modification made since the last call to AcceptChanges.

WriteXML()

Writes an XML schema and data from the DataSet. This function has different overloaded forms.

WriteXMLSchema()

Writes the structure of the DataSet as an XML schema. This function has different overloaded forms.

The DataTable Class:

The DataTable class shows the tables in the database. It has the following important properties; most of these properties are read only types except the PrimaryKey property:

Properties

Description

ChildRelations

Gives the collection of child relationship.

Columns

Gives the Columns collection.

Constraints

Gives the Constraints collection.

DataSet

Gives the parent DataSet.

DefaultView

Gives a view of the table .

ParentRelations

Gives the ParentRelations collection.

PrimaryKey

Gets or sets an array of columns as the primary key for the table.

Rows

Gives the Rows collection.

Following table shows some important methods of the DataTable class:

Methods

Description

AcceptChanges

Commits all changes since the last AcceptChanges.

Clear

Clears all data from the table.

GetChanges

Gives a copy of the DataTable with all changes made since the AcceptChanges method was called.

GetErrors

Gives an array of rows with errors.

ImportRows

Copies a new row into the table.

LoadDataRow

Searches and updates a specific row, or creates a new one, if not found any.

Merge

Merges the table with another DataTable.

NewRow

Prepares a new DataRow.

RejectChanges

Rolls back all modification made since the last call to AcceptChanges.

Reset

Resets the table to its real state.

Select

Provides an array of DataRow objects.

The DataRow Class:

The DataRow object signifies a row in a table. It has the subsequent important properties:

Properties

Description

HasErrors

Shows if there are any errors .

Items

Sets or gets the data stored in a specific column .

ItemArrays

Sets or gets all the values for the row.

Table

Provides the parent table .

Following table shows some important methods of the DataRow class:

Methods

Description

AcceptChanges

Accepts all modification made since this method was called.

BeginEdit

Takes edit operation.

CancelEdit

Cancels edit operation.

Delete

Eliminates the DataRow .

EndEdit

Ends the edit operation.

GetChildRows

Takes the child rows of this row.

GetParentRow

Gets the parent row.

GetParentRows

Gets parent rows of DataRow object.

RejectChanges

Rolls back all modifications made since the last call to AcceptChanges.

The DataAdapter Object:

The DataAdapter object behaves as a mediator between the DataSet object and the database. This helps the data set to have data from more than one database or other data source.

The DataReader Object:

The DataReader object is an another way to the DataSet and DataAdapter combination. This object gives a connection oriented access to the data records in the database. These objects are suitable for read-only accesses, such as increasing a list and then breaking the connection.

DbCommand and DbConnection Objects:

The DbConnection object shows a connection to the data source. The connection may be shared among different command elements.

The DbCommand object shows the command or a stored method sent to the database from getting or manipulating data.

Example:

So far, we have used tables and databases already having in our computer. In this example, we will prepare a table, add column, rows and data into it and show the table using a GridView object.

The source file:

<%@ Page Language="C#"

         AutoEventWireup="true"

         CodeBehind="Default.aspx.cs"

         Inherits="createdatabase._Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

     "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="https://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

 

        <asp:GridView ID="GridView1" runat="server">

        </asp:GridView>

 

    </div>

    </form>

</body>

</html>

The code behind file:

namespace createdatabase

{

   public partial class _Default : System.Web.UI.Page

   {

      protected void Page_Load(object sender, EventArgs e)

      {

         if (!IsPostBack)

         {

            DataSet ds = CreateDataSet();

            GridView1.DataSource = ds.Tables["Student"];

            GridView1.DataBind();

         }

      }

      private DataSet CreateDataSet()

      {

         //creating a DataSet object for tables

         DataSet dataset = new DataSet();

 

         // creating the student table

         DataTable Students = CreateStudentTable();

         dataset.Tables.Add(Students);

         return dataset;

      }

      private DataTable CreateStudentTable()

      {

         DataTable Students = new DataTable("Student");

 

         // adding columns

         AddNewColumn(Students, "System.Int32", "StudentID");

         AddNewColumn(Students, "System.String", "StudentName");

         AddNewColumn(Students, "System.String", "StudentCity");

 

         // adding rows

         AddNewRow(Students, 1, "M H Kabir", "Kolkata");

         AddNewRow(Students, 1, "Shreya Sharma", "Delhi");

         AddNewRow(Students, 1, "Rini Mukherjee", "Hyderabad");

         AddNewRow(Students, 1, "Sunil Dubey", "Bikaner");

         AddNewRow(Students, 1, "Rajat Mishra", "Patna");

 

         return Students;

      }

 

      private void AddNewColumn(DataTable table,

                                string columnType,

                                string columnName)

      {

         DataColumn column = table.Columns.Add(columnName,

                                 Type.GetType(columnType));

      }

 

      //adding data into the table

      private void AddNewRow(DataTable table, int id,

                            string name, string city)

      {

When you run the program observe the following:

  • The application first makes a data set and binds it with the grid view control needing the DataBind() function of the GridView control.
  • The Createdataset() function is a user described function, which prepares a new DataSet object and then calls anther user defined function CreateStudentTable() to build the table and add it to the Tables collection of the data set.
  • The CreateStudentTable() prepare calls the user described methods AddNewColumn() and AddNewRow() to prepare the columns and rows for the table as well as to include data to the rows.

When the page is run, it provides the rows of the table so created:

 

1102_ado.net1.png

 

Email based ASP.Net assignment help - homework help at Expertsmind

Are you searching ASP.Net expert for help with ADO.NET questions?  ADO.NET topic is not easier to learn without external help?  We at www.expertsmind.com offer finest service of ASP.Net assignment help and ASP.Net homework help. Live tutors are available for 24x7 hours helping students in their ADO.NET related problems. Computer science programming assignments help making life easy for students. We provide step by step ADO.NET question's answers with 100% plagiarism free content. We prepare quality content and notes for ADO.NET topic under ASP.Net theory and study material. These are avail for subscribed users and they can get advantages anytime.

Why Expertsmind for assignment help

  1. Higher degree holder and experienced experts network
  2. Punctuality and responsibility of work
  3. Quality solution with 100% plagiarism free answers
  4. Time on Delivery
  5. Privacy of information and details
  6. Excellence in solving ASP.Net queries in excels and word format.
  7. Best tutoring assistance 24x7 hours

 

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd