标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; using MyShoolModels; namespace MyShoolDAL { public class DBhelper { string conn = "Data Source=.;Initial Catalog=MySchool;User ID=sa"; SqlConnection sc; public SqlConnection Sc//连接 { get { if(sc==null) { sc = new SqlConnection(conn); } return sc; } } public void OpenSc() //打开 { if(sc.State==System.Data.ConnectionState.Broken || sc.State==System.Data.ConnectionState.Closed) { sc.Close(); sc.Open(); } } public void CloseSc()//关闭 { if (sc.State == System.Data.ConnectionState.Broken || sc.State == System.Data.ConnectionState.Open) { sc.Close(); } } public int ExecuteQue(string sql,SqlParameter[] paras) { SqlCommand cmd = new SqlCommand(sql,Sc); cmd.Parameters.AddRange(paras); int resul = cmd.ExecuteNonQuery(); return resul; } } }
标签:
原文地址:http://www.cnblogs.com/rapperx2/p/5671814.html