SQL Server Returns a dataset datareader

Source: Internet
Author: User

Visual C # tutorial on Dynamically Operating SQL Server database instances (5): Method for returning a dataset datareader

As described aboveSQL statement execution method with ParametersAndHow to execute a stored procedure with Parameters, This article introducesMethod for returning the dataset datareader, It callsSqlhelper)Run the sqlhelper. executereader () method. The example is;

Sqldatareader mydr = sqlhelper. executereader (sqlhelper. connectionstringlocaltransaction, commandtype. Text, SQL, null );

The four parameters are passed:

"Sqlhelper. connectionstringlocaltransaction ,"-Call the generic data handler class, Returns the link string;

"Commandtype. Text"-indicates the type of SQL command to be executed;

"SQL"-the SQL command statement to be executed;

"Null"-the fourth parameter is null.

Protected void btnexecutereader_click (Object sender, eventargs E)
{
// Obtain the command to be executed
String SQL = "select top 5 title, classname, hints, dateantime, ArticleID, classid_a, classid, classid_c from menularticle where classid_a = 1 and headline = 1 order by hints DESC ";
Sqlcommand cmd = new sqlcommand ();
// Defines the storage range of object Resources. Once the using range ends, the resources occupied by the other party are released.

// Call the execution method. Because there is no parameter, the last item is directly set to null.
// Note: The returned result is of the sqldatareader type.
Sqldatareader mydr = sqlhelper. executereader (sqlhelper. connectionstringlocaltransaction, commandtype. Text, SQL, null );
// Assign the result to datalist as its Data Source
Datalist1.datasource = mydr;
// Bind data
Datalist1.databind ();
}

For more information, see my website.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.