日期:2014-05-16 浏览次数:20548 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//
using System.Data;
using System.Data.SqlClient;
namespace DBManger
{
public class DBManagerBase
{
//在基类中声明一个接口对象
protected IDbConnection conn;
}
public class DBManagerSqlServer : DBManagerBase
{
public DBManagerSqlServer(string _connStr)
{
conn = new SqlConnection(_connStr);
}
public void insert(string sqlStr)
{
//每次使用时转换一次,优点代码少,但是不知道转换的代价是多少
SqlCommand cmd = new SqlCommand(sqlStr, (SqlConnection)conn);
}
}
}
namespace DBManger
{
public class DBManagerBase
{
}
public class DBManagerSqlServer : DBManagerBase
{
//在继承类中声明对象
protected SqlConnection conn;
public DBManagerSqlServer(string _connStr)
{
conn = new SqlConnection(_connStr);
}
public void insert(string sqlStr)
{
//不需要转换,效率最高
SqlCommand cmd = new SqlCommand(sqlStr, conn);
}
}
}