<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      在web.config中創建數據庫連接

      [摘要]在asp.net應用程序下找到web.config文件,在<system.web>前面加入下面的代碼:<?xml version="1.0" encoding="utf-8"?><configuration> <...

      在asp.net應用程序下找到web.config文件,在<system.web>前面加入下面的代碼:
      <?xml version="1.0" encoding="utf-8"?>
      <configuration>



          <appSettings>
              <add key="ConnectionString" value="server=jeff;uid=sa;pwd=btk;database=msg" />
          </appSettings> 
         
        <system.web>
       ......
        </system.web>
      </configuration>   



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




      日韩精品一区二区三区高清