如何在web.config中建立公用的的数据库连接
2006-04-02 10:33
519 查看
<configuration>
<!-- application specific settings -->
<appSettings>
<add key=ConnectionString value=server=localhost;uid=sa;pwd=;database=store />
</appSettings>
<configuration>
public SqlDataReader GetReviews(int productID) {
// 创建Connection和Command对象实例
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings[ConnectionString]);
SqlCommand myCommand = new SqlCommand(ReviewsList, myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
// 参数
SqlParameter parameterProductID = new SqlParameter(@ProductID, SqlDbType.Int, 4);
parameterProductID.Value = productID;
myCommand.Parameters.Add(parameterProductID);
// 执行
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
// 返回结果
return result;
数据库连接;return true>
<!-- application specific settings -->
<appSettings>
<add key=ConnectionString value=server=localhost;uid=sa;pwd=;database=store />
</appSettings>
<configuration>
public SqlDataReader GetReviews(int productID) {
// 创建Connection和Command对象实例
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings[ConnectionString]);
SqlCommand myCommand = new SqlCommand(ReviewsList, myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
// 参数
SqlParameter parameterProductID = new SqlParameter(@ProductID, SqlDbType.Int, 4);
parameterProductID.Value = productID;
myCommand.Parameters.Add(parameterProductID);
// 执行
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
// 返回结果
return result;
数据库连接;return true>
相关文章推荐
- 如何在web.config中建立公用的的数据库连接
- 如何在web.config中建立公用的的数据库连接
- 关于如何得到web.config中的数据库连接字符串
- C#中如何读取webconfig.xml里的数据库连接字符串
- 在web.config中如何配置数据库连接字符串,较为安全?
- 在web.config中如何配置数据库连接字符串,较为安全?
- WebService如何从Web.Config中读取数据库连接字符串
- 在web.config中建立数据库连接
- 关于如何得到web.config中的数据库连接字符串
- Acess数据库连接字符串如何存放在Web.config中?
- NET中使用三层构架如何从DAL层读取web.config中的数据库连接字符串!
- [导入].NET中使用三层构架如何从DAL层读取web.config中的数据库连接字符串!
- 数据库连接字在Web.config里的用法
- 搞定 .NET web.config 数据库连接设置
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法
- 从Web.config文件中读取数据库连接的字符串
- 如何:从Web.config 文件读取连接字符串
- web.config配置数据库连接
- 如何加密Web.Config中的连接字符串
- web.config配置数据库连接(转)