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

首頁 > 編程 > .NET > 正文

.net MVC 連接數據本地數據庫三種方法總結

2024-07-10 12:49:34
字體:
來源:轉載
供稿:網友

.net MVC 連接數據本地數據庫三種方法

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 厦门市| 卢湾区| 定兴县| 武隆县| 容城县| 怀来县| 海晏县| 五大连池市| 黔江区| 宣武区| 南昌市| 凤凰县| 临洮县| 桃源县| 英山县| 新宁县| 汾阳市| 大洼县| 宿迁市| 汾西县| 乌海市| 和平区| 环江| 和静县| 确山县| 科技| 龙海市| 盈江县| 明星| 车险| 汾阳市| 竹北市| 盱眙县| 来安县| 鄢陵县| 隆尧县| 高安市| 攀枝花市| 万山特区| 福贡县| 高陵县|