强烈建议使用微软企业库,而不要用什么SqlHelper之类的东东,在引用了Microsoft.Practices.EnterpriseLibrary.Data.dll和Microsoft.Practices.EnterpriseLibrary.Common.dll后,在webconfig里面配置节点
然后在代码里使用
//创建Database对象
Database db = DatabaseFactory.CreateDatabase();
//创建DbCommand对象
DbCommand dbCommand = db.GetStoredProcCommand("UP_APKeyHistory_Query");
//添加输入输出参数
db.AddInParameter(dbCommand, "@APID", DbType.String, apq.APID);
db.AddInParameter(dbCommand, "@CommunicationKey", DbType.String, apq.CommunicationKey);
db.AddInParameter(dbCommand, "@MaxEffectiveTime", DbType.DateTime, apq.MaxEffectiveTime);
db.AddInParameter(dbCommand, "@MinEffectiveTime", DbType.DateTime, apq.MinEffectiveTime);
db.AddInParameter(dbCommand, "@MaxExpiredTime", DbType.String, apq.MaxExpiredTime);
db.AddInParameter(dbCommand, "@MinExpiredTime", DbType.String, apq.MinExpiredTime);
db.AddInParameter(dbCommand, "@KeyStatus", DbType.String, apq.KeyStatus);
List
//执行命令返回DataReader对象
using (IDataReader dr = db.ExecuteReader(dbCommand))
{
while (dr.Read())
{
APKeyList.Add(CreateAPKeyHistoryInfo(dr));
}
}
return APKeyList;
强烈建议使用微软企业库,而不要用什么SqlHelper之类的东东,在引用了Microsoft.Practices.EnterpriseLibrary.Data.dll和Microsoft.Practices.EnterpriseLibrary.Common.dll后,在webconfig里面配置节点
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data,
Version=4.1.0.0,
Culture=neutral"
/>
/>
connectionString="server=10.192.56.112;
user
id=sa;
password
=sa;
database
=KDSW"
providerName="System.Data.SqlClient"
/>
然后在代码里使用
//创建Database对象
Database
db
=
DatabaseFactory.CreateDatabase();
//创建DbCommand对象
DbCommand
dbCommand
=
db.GetStoredProcCommand("UP_APKeyHistory_Query");
//添加输入输出参数
db.AddInParameter(dbCommand,
"@APID",
DbType.String,
apq.APID);
db.AddInParameter(dbCommand,
"@CommunicationKey",
DbType.String,
apq.CommunicationKey);
db.AddInParameter(dbCommand,
"@MaxEffectiveTime",
DbType.DateTime,
apq.MaxEffectiveTime);
db.AddInParameter(dbCommand,
"@MinEffectiveTime",
DbType.DateTime,
apq.MinEffectiveTime);
db.AddInParameter(dbCommand,
"@MaxExpiredTime",
DbType.String,
apq.MaxExpiredTime);
db.AddInParameter(dbCommand,
"@MinExpiredTime",
DbType.String,
apq.MinExpiredTime);
db.AddInParameter(dbCommand,
"@KeyStatus",
DbType.String,
apq.KeyStatus);
List
APKeyList
=
new
List
//执行命令返回DataReader对象
using
(IDataReader
dr
=
db.ExecuteReader(dbCommand))
{
while
(dr.Read())
{
APKeyList.Add(CreateAPKeyHistoryInfo(dr));
}
}
return
APKeyList;
webconfig里面
string connectionString = ConfigurationManager.AppSettings[configName];
写在webconfig里面