特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> ASP.NET教程> 如何在web.config中建立公用的的数据库连接

如何在web.config中建立公用的的数据库连接

时间:2009-06-30 16:14:10 作者:互联网


   
   
       
   

public SqlDataReader GetReviews(int productID) {

    // 创建Connection和Command对象实例
    SqlConnection myConnection = new SqlConnection(Co***gurationSettings.AppSettings[ConnectionString]);
    SqlCommand myCommand = new SqlCommand(ReviewsList, myConnection);

    my***mand.CommandType = Co***ndType.StoredProcedure;

    // 参数
    SqlParameter parameterProductID = new SqlParameter(@ProductID, Sq***Type.Int, 4);
    pa***eterProductID.Value = productID;
    my***mand.Parameters.Add(parameterProductID);

    // 执行
    my***nection.Open();
    SqlDataReader result = my***mand.ExecuteReader(Co***ndBehavior.CloseConnection);

    // 返回结果
    return result;
数据库连接;return true>

 

相关文章 最新文章

相关应用

热门文章

猜你喜欢

返回顶部