SQLDATAREADER
Introduction
The sqldatareader is the object we use in the ado.net for accepting or retrieving the row of a table from the database.
The syntax is,
sqldatareader sqlDr = sqlcommandtype.executereader;
the sqldatareader will read the value row by row and we need to open the connection and close the connection.
As we use the void return type in function call, here we need to specify the return type there are three types of return value,
ExecuteNonQuey
ExecuteScalar
ExecuteReader
The execute reader is used to get the single value from the data table.
The execute scalar is used for the single row retrieval query like aggregate function().
The ExecuteNonQuery will not return the value like void.
example, if we need to get the value of a data cell from one data table,
sqlconnection con = new sqlconnection("connection string");
con.open();
sqlcommand cmd = new sqlcommand("select * from tablename where empid = '100'",con);
sqldatareader dr = cmd.executereader();
if(dr.read) //if data reader have any data or record
{
label.text =Convert.ToString( dr[0]["columnName"] );
}
con.Close();
****************************************************************************************************************
Introduction
The sqldatareader is the object we use in the ado.net for accepting or retrieving the row of a table from the database.
The syntax is,
sqldatareader sqlDr = sqlcommandtype.executereader;
the sqldatareader will read the value row by row and we need to open the connection and close the connection.
As we use the void return type in function call, here we need to specify the return type there are three types of return value,
ExecuteNonQuey
ExecuteScalar
ExecuteReader
The execute reader is used to get the single value from the data table.
The execute scalar is used for the single row retrieval query like aggregate function().
The ExecuteNonQuery will not return the value like void.
example, if we need to get the value of a data cell from one data table,
sqlconnection con = new sqlconnection("connection string");
con.open();
sqlcommand cmd = new sqlcommand("select * from tablename where empid = '100'",con);
sqldatareader dr = cmd.executereader();
if(dr.read) //if data reader have any data or record
{
label.text =Convert.ToString( dr[0]["columnName"] );
}
con.Close();
****************************************************************************************************************
No comments:
Post a Comment