qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請?jiān)L問 http://qaseven.github.io/

          web.config配置文件鏈接數(shù)據(jù)庫的方法

            【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 閱讀(404) 評論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫

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

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 长顺县| 兴国县| 玉环县| 洮南市| 苏尼特左旗| 余庆县| 石门县| 中卫市| 建湖县| 邹城市| 油尖旺区| 泰安市| 大方县| 美姑县| 资中县| 荥经县| 岳池县| 三原县| 云浮市| 柘城县| 庄河市| 彰化市| 酒泉市| 元阳县| 昌乐县| 河北省| 百色市| 定兴县| 灵川县| 济宁市| 合水县| 三门县| 丰都县| 高阳县| 嵊泗县| 徐闻县| 晋城| 五常市| 金溪县| 古蔺县| 大英县|