using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient;
namespace 第五章的实例
{ class DBHelp
{ private SqlConnection con; public SqlConnection Con
{ get
{ string sql = "Data Source=.;
Initial Catalog=MySchool;
User ID=sa;Password=131479";
if (con == null)
{ con = new SqlConnection(sql);
}
return con;
} } public void Open()
{ if (con.State == ConnectionState.Closed)
{ con.Open();
} else if (con.State == ConnectionState.Broken)
{ con.Close(); con.Open();
} } public void Close()
{ if (con.State == ConnectionState.Open || con.State == ConnectionState.Broken)
{ con.Close();
}
}
} }