zoukankan      html  css  js  c++  java
  • winform的DBhelper

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using System.Data;

    namespace TicketSystem
    {
       public class DBHelper
        {
           string conStr = "Data Source=.;Initial Catalog=Ticket;Integrated Security=True";
           private SqlConnection _connection;
           /// <summary>
           /// 公共属性,获取连接对象
           /// </summary>
           public SqlConnection Connection {
               get{
                    if(_connection==null){
                        _connection=new SqlConnection(conStr);
                    }
                   return _connection;
               }
              
             
           }
           /// <summary>
           /// 打开数据库连接
           /// </summary>
           public void OpenConnect() {
               if (_connection.State == ConnectionState.Closed)//关闭状态
               {
                   _connection.Open();
               }
               else if (_connection.State == ConnectionState.Broken)//断开状态
               {
                   _connection.Close();
                   _connection.Open();
               }
           }
          /// <summary>
           /// 关闭数据库连接
          /// </summary>
           public void CloseConnect() {
               if (_connection.State == ConnectionState.Open
                   || _connection.State == ConnectionState.Broken)
               {
                   _connection.Close();
               }
           }
       }
    }

  • 相关阅读:
    免费录屏工具
    树莓派4安装mysql
    python中,print、变量、赋值详细理解篇01
    mysql db [Warning] IP address 'xxxx' could not be resolved: Name or service not known
    添加脚本命令
    LRUCache实现方案
    HTTP/2做错了什么?刚刚辉煌2年就要被弃用了!?
    TS 中的 export declare interface 和 export interface 到底有什么不同?
    使用nexus搭建npm私服
    nodejs 安装
  • 原文地址:https://www.cnblogs.com/a1111/p/6041098.html
Copyright © 2011-2022 走看看