国产探花免费观看_亚洲丰满少妇自慰呻吟_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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 庄浪县| 顺平县| 晋宁县| 百色市| 襄垣县| 阜新| 清水县| 潜山县| 和硕县| 来安县| 开封市| 瓮安县| 永康市| 林州市| 东辽县| 运城市| 北辰区| 茂名市| 嘉善县| 滦平县| 汨罗市| 宝清县| 城固县| 博白县| 贵州省| 舟山市| 全椒县| 灵璧县| 松溪县| 南通市| 平阳县| 阜南县| 区。| 莱州市| 沂源县| 鲜城| 芦山县| 达尔| 达尔| 凯里市| 德阳市|