最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在web.config中建立数据库连接
时间:2022-07-02 11:27:25 编辑:袖梨 来源:一聚教程网
在应用程序下找到web.config文件,在前面加入下面的代码:
......
在aspx文件里面建立连接:
public SqlDataReader GetReviews(int productID) {
// 创建Connection和Command对象实例
SqlConnection myConnection = new SqlConnection(System.Configuration.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;
}
......
在aspx文件里面建立连接:
public SqlDataReader GetReviews(int productID) {
// 创建Connection和Command对象实例
SqlConnection myConnection = new SqlConnection(System.Configuration.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;
}
相关文章
- 深渊之潮兑换码分享 深渊之潮最新2025兑换码大全 10-11
- 恶魔轮盘兑换码是什么 恶魔轮盘最新2025兑换码一览 10-11
- 死亡日狂杀末路兑换码有什么 死亡日狂杀末路最新2025兑换码分享 10-11
- 伊瑟公测兑换码有哪些 伊瑟2025最新可用兑换码汇总 10-11
- 快餐模拟器兑换码分享 快餐模拟器最新2025兑换码一览 10-11
- 纸房子角色攻略大全 纸房子全路线结局选项分享 10-11