Tip: (3) How does Asp.net connect SQL and access?

Source: Internet
Author: User

1. SQL dataview

Public Dataview getview ( String Query, String Connstr, Int Startrcd, Int Pagesize)
{
Sqlconnection connection = New Sqlconnection (connstr );
Sqldataadapter myadp = New Sqldataadapter (query, connection );
Dataset tableset = New Dataset ();
Myadp. Fill (tableset, " Alltable " );
Myadp. Fill (tableset, startrcd, pagesize, " Istable " );
Dataview isview = New Dataview ();
Isview. Table = Tableset. Tables [ " Alltable " ];
Maxselect = Isview. count;
Isview. Table = Tableset. Tables [ " Istable " ];
Return Isview;
Tableset. Tables [ 0 ]. Select ();
}

Datareader
Public Sqldatareader getreader ( String Query, String Connstr)
{
Sqlconnection connection = New Sqlconnection (connstr );
Sqlcommand mycom = New Sqlcommand (query, connection );
Connection. open ();
Sqldatareader isreader = Mycom. executereader ();
Return Isreader;
}

Nonequery

Public   Int Nonequery ( String Query, String Connstr)
{
Sqlconnection connection = New Sqlconnection (connstr );
Sqlcommand command = New Sqlcommand (query, connection );
Connection. open ();
Int N = Command. executenonquery ();
Connection. Close ();
Return N;
}

this name is used to connect to access. It is very convenient to create a class.

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.