国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.net MVC 連接數(shù)據(jù)本地?cái)?shù)據(jù)庫三種方法總結(jié)

2024-07-10 13:31:35
字體:
供稿:網(wǎng)友

.net MVC 連接數(shù)據(jù)本地?cái)?shù)據(jù)庫三種方法

  <appSettings>   <add key="webpages:Version" value="2.0.0.0" />   <add key="webpages:Enabled" value="false" />   <add key="PreserveLoginUrl" value="true" />   <add key="ClientValidationEnabled" value="true" />   <add key="UnobtrusiveJavaScriptEnabled" value="true" />   <add key="con" value="server=./sqlexpress; user id = sa;password = a123456;database = xsgl1;max pool size=512;"/>  </appSettings>  <connectionStrings>   <add name="conSql" connectionString="server=(local)/sqlexpress; User Id = sa;password = a123456;database = xsgl1;max pool size=512;"/>  </connectionStrings> Configuration
  public class HomeController : Controller   {     //     // GET: /Home/      public ActionResult Index()     {       #region connect sql function one       SqlConnectionStringBuilder one = new SqlConnectionStringBuilder();       one.DataSource = "(local)//sqlexpress";      one.InitialCatalog = "xsgl1";       one.UserID = "sa";       one.Password = "a123456";       one.MaxPoolSize = 512;       SqlConnection sct = new SqlConnection(one.ConnectionString);       #endregion       #region connect sql function two       //string conn = ConfigurationManager.AppSettings["con"].ToString();       //SqlConnection sct = new SqlConnection(conn);       #endregion       #region connect sql function three       //string conn = ConfigurationManager.ConnectionStrings["conSql"].ConnectionString;       //SqlConnection sct = new SqlConnection(conn);       #endregion       SqlCommand scm = new SqlCommand();       scm.Connection = sct;      scm.CommandType = CommandType.Text;       scm.CommandText = "select 課程名 from kc where 課程號='A001'";       sct.Open();       SqlDataReader sdr = scm.ExecuteReader();       if (sdr.Read())       {        ViewBag.hao = sdr["課程名"];      }      sdr.Close();      return View();    }    public ActionResult About()    {      return View();     }   }Controller
@{  ViewBag.Title = "Index"; } @ViewBag.hao <h2>Index</h2>


注:相關(guān)教程知識閱讀請移步到ASP.NET教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大丰市| 林芝县| 柳江县| 玛曲县| 永川市| 和平县| 墨玉县| 葵青区| 葫芦岛市| 洱源县| 峨眉山市| 唐河县| 昌图县| 伽师县| 松潘县| 千阳县| 营山县| 泰州市| 平顺县| 昌都县| 东城区| 新源县| 牡丹江市| 苗栗县| 文安县| 巴里| 微博| 驻马店市| 麦盖提县| 浮山县| 四会市| 金川县| 渝北区| 南宫市| 长白| 安阳市| 嘉鱼县| 班戈县| 松阳县| 正定县| 广饶县|