DAL 数据链路层 非查询/查询
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 //非查询 {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(); //查询一批值 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); //查询一个值 dx.Parameters.Add(arr.ToArray()); return dx.ExecuteScalar(); }