程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 如何在web.config中建立公用的的數據庫連接

如何在web.config中建立公用的的數據庫連接

編輯:.NET實例教程


<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>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved