大家看看这种单态模式能行吗?
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Common
{
public class DBCom
{
//取得一个数据库的连接
public static SqlConnection GetConnection()
{
SqlConnection sqlconn = new SqlConnection();
try
{
sqlconn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings[1].ConnectionString;
return sqlconn;
}
catch(SqlException e)
{
System.Console.WriteLine( e.Message.ToString());
return null;
}
}
//========================================================================
//执行sql语句返回所影响的行数
public static int ExecuteSql(string sql)
{
SqlConnection conn = DBCom.GetConnection();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sql.Trim();
try
{
conn.Open();
int count = cmd.ExecuteNonQuery();
return count;