qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          web.config配置文件鏈接數據庫的方法

            【1】在web.config配置文件中,
          <connectionStrings>
          <add name="NorthwindConnectionString" connectionString="Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=sa"
          providerName="System.Data.SqlClient" />
          </connectionStrings>
            【2】在后臺中,引入程序集或者手工引入:using System.Web.Configuration;
            【3】后臺寫入的方法為:
          protected void Page_Load(object sender, EventArgs e)
          {
          //從web.config中引用連接字符串
          string strConn = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
          SqlConnection myConn = new SqlConnection(strConn);
          string strSQL = "SELECT Top 5 CategoryID,CategoryName,Description From Categories";
          SqlCommand myCommand = new SqlCommand(strSQL, myConn);
          myConn.Open();
          myGv.DataSource = myCommand.ExecuteReader();
          myGv.DataBind();
          myConn.Close();
          }

          posted on 2013-10-29 10:40 順其自然EVO 閱讀(406) 評論(0)  編輯  收藏 所屬分類: 數據庫

          <2013年10月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 海南省| 枣庄市| 延庆县| 钟山县| 松滋市| 汉中市| 绵阳市| 玛曲县| 嘉荫县| 邳州市| 平原县| 滁州市| 罗山县| 自治县| 瓮安县| 南溪县| 株洲市| 镇远县| 郁南县| 济阳县| 辛集市| 克拉玛依市| 新乡县| 托克托县| 邢台市| 四川省| 勃利县| 长宁县| 乌兰浩特市| 梅河口市| 台北县| 濉溪县| 澄城县| 大名县| 来安县| 新宁县| 北碚区| 华蓥市| 隆子县| 平安县| 高雄市|