Source code display: ASP. NET data category

Source: Internet
Author: User

/// Execute the stored procedure with parameters and return the data set
/// </Summary>
/// <Param name = "procname"> stored procedure name </param>
/// <Param name = "Parameters"> sqlparametercollection input parameters </param>
/// <Returns> </returns>
Public static datatable (string procname, sqlparametercollection parameters)
{
Sqldataadapter da = new sqldataadapter ();
Datatable = new datatable ();
Try
{
Openconnection ();
Comm. Parameters. Clear ();
Comm. commandtype = commandtype. storedprocedure;
Comm. commandtext = procname;
Foreach (sqlparameter para in parameters)
{
Sqlparameter P = (sqlparameter) para;
Comm. Parameters. Add (P );
}
Da. selectcommand = comm;
Da. Fill (datatable );
}
Catch (exception E)
{
Throw new exception (E. Message );
}
Finally
{
Closeconnection ();
}
Return datatable;
}

Public static dataview (string sqlstr)
{
Sqldataadapter da = new sqldataadapter ();
Dataview DV = new dataview ();
Dataset DS = new dataset ();
Try
{
Openconnection ();
Comm. commandtype = commandtype. text;
Comm. commandtext = sqlstr;
Da. selectcommand = comm;
Da. Fill (DS );
DV = Ds. Tables [0]. defaultview;
}
Catch (exception E)
{
Throw new exception (E. Message );
}
Finally
{
Closeconnection ();
}
Return DV;
}
}

}

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.