首页 > 数据库技术 > 详细

DBHelp数据处理类

时间:2016-07-14 23:51:20      阅读:380      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!