码迷,mamicode.com
首页 > 数据库 > 详细

DBHelp数据处理类

时间:2016-07-14 23:51:35      阅读:324      评论:0      收藏:0      [点我收藏+]

标签:

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;
        }
    }
}

 

DBHelp数据处理类

标签:

原文地址:http://www.cnblogs.com/rapperx2/p/5671814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!