Three layer Architecture DAL layer Basic code non-query/query

Source: Internet
Author: User

DAL Data Link Layer non-query/query

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Data;
Using System.Data.SqlClient;


Namespace DAL
{
public class SqlHelper//Non-query
{

public static int Baba (string sql,list<sqlparameter>paras)

{


SqlConnection conn = new SqlConnection ("server=.; Database=schoolido;uid=sa;pwd=123 ");
Conn. Open ();
SqlCommand cmd = new SqlCommand (SQL, conn);
Cmd. Parameters.addrange (paras. ToArray ());
return CMD. ExecuteNonQuery ();


}

}
}

public static DataTable name (String sql, list<sqlparameter> arr)
{
DataSet set = new DataSet ();
SqlConnection conn = new SqlConnection (); Querying a batch of values
Conn. Open ();
SqlCommand dx = new SqlCommand (SQL, conn);
Dx. Parameters.addrange (arr. ToArray ());
SqlDataAdapter haha = new SqlDataAdapter (DX);
haha. Fill (set);
return set. Tables[0];





}
public static object name (String sql, list<sqlparameter> arr)
{


SqlConnection conn = new SqlConnection ("");
SqlCommand dx = new SqlCommand (sql,conn); Querying a value
Dx. Parameters.Add (arr. ToArray ());
Return DX. ExecuteScalar ();


}

Three layer Architecture DAL layer Basic code non-query/query

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.