using
System;
using System.Data;
namespace Lem_DALFactory
... {
/**//// <summary>
/// ICommandAccess 的摘要说明。
/// </summary>
public interface ICommonAccess
...{
//传入增,删,改的SQL语句
string GetExCmd(string strSql);
//传入一条查询语句,和一个表名
DataSet GetDs(string strSql,string TableName);
//传入一个查询语句,返回首行首列,用于登陆
int GetSearch(string strSql);
}
}
using System.Data;
namespace Lem_DALFactory
... {
/**//// <summary>
/// ICommandAccess 的摘要说明。
/// </summary>
public interface ICommonAccess
...{
//传入增,删,改的SQL语句
string GetExCmd(string strSql);
//传入一条查询语句,和一个表名
DataSet GetDs(string strSql,string TableName);
//传入一个查询语句,返回首行首列,用于登陆
int GetSearch(string strSql);
}
}
using
System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Lem_DALFactory
... {
/**//// <summary>
/// SqlProvider 的摘要说明。
/// </summary>
public class SqlProvider:ICommonAccess
...{
SqlConnection conn=null;
public SqlProvider()
...{
conn=new SqlConnection(ConfigurationSettings.AppSettings["conn"]);
}
ICommandAccess 成员#region ICommandAccess 成员
public string GetExCmd(string strSql)
...{
SqlCommand cmd=new SqlCommand(strSql,conn);
conn.Open();
int i=cmd.ExecuteNonQuery();
string str="";
if(i>0)
...{
str="操作成功";
}
else
...{
str="操作失败";
}
return str;
}
public DataSet GetDs(string strSql,string TableName)
...{
SqlDataAdapter da=new SqlDataAdapter(strSql,conn);
DataSet ds=new DataSet();
da.Fill(ds,TableName);
return ds;
}
public int GetSearch(string strSql)
...{
SqlCommand cmd=new SqlCommand(strSql,conn);
conn.Open();
int i=int.Parse(cmd.ExecuteScalar().ToString());
return i;
}
#endregion
}
}
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace Lem_DALFactory
... {
/**//// <summary>
/// SqlProvider 的摘要说明。
/// </summary>
public class SqlProvider:ICommonAccess
...{
SqlConnection conn=null;
public SqlProvider()
...{
conn=new SqlConnection(ConfigurationSettings.AppSettings["conn"]);
}
ICommandAccess 成员#region ICommandAccess 成员
public string GetExCmd(string strSql)
...{
SqlCommand cmd=new SqlCommand(strSql,conn);
conn.Open();
int i=cmd.ExecuteNonQuery();
string str="";
if(i>0)
...{
str="操作成功";
}
else
...{
str="操作失败";
}
return str;
}
public DataSet GetDs(string strSql,string TableName)
...{
SqlDataAdapter da=new SqlDataAdapter(strSql,conn);
DataSet ds=new DataSet();
da.Fill(ds,TableName);
return ds;
}
public int GetSearch(string strSql)
...{
SqlCommand cmd=new SqlCommand(strSql,conn);
conn.Open();
int i=int.Parse(cmd.ExecuteScalar().ToString());
return i;
}
#endregion
}
}
using
System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
namespace Lem_DALFactory
... {
/**//// <summary>
/// OdbcProvider 的摘要说明。
/// </summary>
public class OleDbProvider:ICommonAccess
...{
OleDbConnection conn=null;
public OleDbProvider()
...{
conn=new OleDbConnection(ConfigurationSettings.AppSettings["conn"]);
}
ICommonAccess 成员#region ICommonAccess 成员
public string GetExCmd(string strSql)
...{
OleDbCommand cmd=new OleDbCommand(strSql,conn);
conn.Open();
int i=cmd.ExecuteNonQuery();
string str="";
if(i>0)
...{
str="操作成功";
}
else
...{
str="操作失败";
}
return str;
}
public System.Data.DataSet GetDs(string strSql, string TableName)
...{
OleDbDataAdapter da=new OleDbDataAdapter(strSql,conn);
DataSet ds=new DataSet();
da.Fill(ds,TableName);
return ds;
}
public int GetSearch(string strSql)
...{
OleDbCommand cmd=new OleDbCommand(strSql,conn);
conn.Open();
int i=int.Parse(cmd.ExecuteScalar().ToString());
return i;
}
#endregion
}
}
using System.Data;
using System.Data.OleDb;
using System.Configuration;
namespace Lem_DALFactory
... {
/**//// <summary>
/// OdbcProvider 的摘要说明。
/// </summary>
public class OleDbProvider:ICommonAccess
...{
OleDbConnection conn=null;
public OleDbProvider()
...{
conn=new OleDbConnection(ConfigurationSettings.AppSettings["conn"]);
}
ICommonAccess 成员#region ICommonAccess 成员
public string GetExCmd(string strSql)
...{
OleDbCommand cmd=new OleDbCommand(strSql,conn);
conn.Open();
int i=cmd.ExecuteNonQuery();
string str="";
if(i>0)
...{
str="操作成功";
}
else
...{
str="操作失败";
}
return str;
}
public System.Data.DataSet GetDs(string strSql, string TableName)
...{
OleDbDataAdapter da=new OleDbDataAdapter(strSql,conn);
DataSet ds=new DataSet();
da.Fill(ds,TableName);
return ds;
}
public int GetSearch(string strSql)
...{
OleDbCommand cmd=new OleDbCommand(strSql,conn);
conn.Open();
int i=int.Parse(cmd.ExecuteScalar().ToString());
return i;
}
#endregion
}
}
using
System;
using System.Configuration;
using System.Reflection;
namespace Lem_DALFactory
... {
/**//// <summary>
/// DataFactory 的摘要说明。
/// </summary>
public class DataFactory
...{
public static ICommonAccess GetCommonAccess()
...{
string path=ConfigurationSettings.AppSettings["provider"];
ICommonAccess CommonAccess=(ICommonAccess)Assembly.Load("Lem_DALFactory").CreateInstance("Lem_DALFactory."+path);
return CommonAccess;
}
}
}
using System.Configuration;
using System.Reflection;
namespace Lem_DALFactory
... {
/**//// <summary>
/// DataFactory 的摘要说明。
/// </summary>
public class DataFactory
...{
public static ICommonAccess GetCommonAccess()
...{
string path=ConfigurationSettings.AppSettings["provider"];
ICommonAccess CommonAccess=(ICommonAccess)Assembly.Load("Lem_DALFactory").CreateInstance("Lem_DALFactory."+path);
return CommonAccess;
}
}
}