Read here
my first artical of ADO.NET Part 1
Method of Command Class :-
1) Executer Reader()
2) ExecuteScaler()
3) ExecuteNonQuery()
Note: after
creating object of command class we need to call any of these 3 method to
execute that statements.
Lets details with all these Method.
1)Call ExecuteReader ( ):-
Method when we want to
execute a “Select statement” that return data as rows and columns.
The method return an object of class Data Reader which contains data
that is retrieved from data Source in the Form of rows and Columns.
2)Call ExecuteScaler ( ) :-
The method when we want
to execute “Select Statement ” that
returns a “single” value result..
The method return the result of the query in the form of object.
3) Call ExecuteNonQuery:-
This Method call when
we want to execute any statement other than select like “Insert,Update,Delete” etc.
This method return
numeric value telling the no of rows affected by the statements.
Accessing Data From DataReader :-
DataReader is a Class which Holds
data in the Form of rows and Coloums to access data From DataReader .
It provide the
Following Method.
1)GetName(int ColIndex) :-
Return type of this method is string ,it Return name of the column for
given index position.
2)Read() : -
Moves Record Pointer from the Current Location to next row and return a
Boolean status which tells whethere the row to which we have moved contains
data in it or not, that will be true if present or false if not present.
3)GetValue(int Colindex) : -
Used
for Returning Coloumns value from the
row to which the pointer was pointing by specifying the column index position.
4)NextResult ()
: -
Moves the record
Pointer from the current table to next table if a table exists and return true
else return false.
Features of Data Reader :-
1) Faster access to data form Data Source ,as it is
connection Orientation.
2) It can hold multiple table hold in it at a time ,to
load multiple table into a Data Reader pass multiple select statements as argument to command
separated by a Colon (;)
Eg.
Command
cmd=new Command(“Select * From Student ;
Select * From
Mark ”, Con);
Data Reader
dr= cmd.ExecuteReader();
Note:-use “NextResult()”
Method of DataReader object to
navigate from Current Table to next Table;
Eg
Dr.NextResult();
DrawBacks of Data Reader :-
1)in the Connection Oriented requires a continuous
Connection with Data Source with Data Source will be access the data, so performance
gets decreased if there are no of
clients accessing data at the same time.
2)it gives only forward direction access to data,ie.it
allows to go either go to next record of table but not to previous record of
table.
For more artical visit my blog
http://dotnetbyabhipatil.blogspot.in
ConversionConversion EmoticonEmoticon