using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
namespace WindowsFormsApplication2
{
class DBHelper
{
private string connString = @"Data Source=.;Initial Catalog=HotelDB;Integrated Security=True";
// 数据库连接 Connection 对象
private SqlConnection connection;
/// <summary>
/// Connection对象
/// </summary>
public SqlConnection Connection
{
get
{
if (connection == null)
{
connection = new SqlConnection(connString);
}
return connection;
}
}
/// <summary>
/// 打开数据库连接
/// </summary>
public void OpenConnection()
{
if (Connection.State == ConnectionState.Closed)
{
Connection.Open();
}
else if (Connection.State == ConnectionState.Broken)
{
Connection.Close();
Connection.Open();
}
}
public void CloseConnection()
{
if (Connection.State == ConnectionState.Open || Connection.State == ConnectionState.Broken)
{
c#开发数据库考试题1
最新推荐文章于 2020-12-13 03:18:12 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)