DBHelp数据处理类

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;
}
}
}
上一篇:C#winfrom最简DBHelp(数据库连接操作)


下一篇:linux下如何查找需要的文件后并删除