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

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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 依安县| 苍山县| 阿拉尔市| 育儿| 宁德市| 金川县| 漳州市| 西吉县| 五大连池市| 洛宁县| 伊宁县| 琼中| 巍山| 沙河市| 承德市| 漳浦县| 宁安市| 来安县| 南皮县| 呼玛县| 武强县| 璧山县| 柳州市| 泰宁县| 新和县| 阿克| 大渡口区| 新干县| 平罗县| 衡山县| 凌海市| 凉山| 郯城县| 石河子市| 乐陵市| 资源县| 金塔县| 宝坻区| 潍坊市| 峡江县| 余干县|