1、通用数据库接口,返回类型为dt
2、字符串类型接口,传入关键字参数,返回类型为字符串
[ServiceContract]
public interface IDataBaseService
{
#region 通用数据库访问接口
[OperationContract]
DataTable ExecuteDataTable(string strSQL);
[OperationContract]
int ExecuteNonQuery(string strSQL);
[OperationContract]
bool ExecuteNonQueryEx(string[] strSQL);
[OperationContract]
object ExecuteScalar(string strSQL);
[OperationContract]
DataTable DataProcess(string strSQL);
[OperationContract]
string DataProcessEx(string command);
#endregion
}
接口的实现类:
public class DataService : IDataBaseService
{
#region 数据库访问通用接口
public DataTable ExecuteDataTable(string strSQL)
{
DataTable dt = new DataTable();
try
{
DbHelper helper = new DbHelper();
dt = helper.ExecuteDataTable(strSQL);
}
catch (Exception ex)
{
throw ex;
}
return dt;
}
public int ExecuteNonQuery(string strSQL)
{
try
{
DbHelper helper = new DbHelper();
return helper.ExecuteNonQuery(strSQL);
}
catch (Exception ex)
{
throw ex;
}
}
public bool ExecuteNonQueryEx(string []strSQL)
{
try
{
DbHelper helper = new DbHelper();
return helper.ExecuteNonQuery(strSQL);
}
catch (Exception ex)
{
throw ex;
}
}
public object ExecuteScalar(string strSQL)
{
try
{
DbHelper helper = new DbHelper();
return helper.ExecuteScalar(strSQL);
}
catch (Exception ex)
{
throw ex;
}
}
public DataTable DataProcess(string strSQL)
{
try
{
return DBService.DataProcess(strSQL);
}
catch (Exception ex)
{
return null;
//throw ex;
}
}
public string DataProcessEx(string command)
{
try
{
return DBService.DataProcessEx(command);
}
catch (Exception ex)
{
return null;
//throw ex;
}
}
#endregion
}