跳到主要內容

發表文章

[MS SQL] SQL CLR 外掛程式

寫C#程式掛在SSMS 1. 寫好 .cs 檔 步驟:新增 SQL Server 專案 --> 在加入 使用者定義函式 --> 撰寫程式 using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; public partial class UserDefinedFunctions {     [Microsoft.SqlServer.Server.SqlFunction]     public static SqlString SqlFunction1()     {         // 將程式碼放在此處         return new SqlString (string.Empty);     } } 2. 在CMD下指令: C:\Windows\Microsoft.NET\Framework\ v3.5 > csc.exe /t:library /out : FunName.dll c:\ FunName .cs //FunName.dll 檔案會在 C:\Windows\Microsoft.NET\Framework\v3.5 3.在SSMS下指令 Use DBName  ALTER DATABASE master SET TRUSTWORTHY ON Go --Create Assembly  --PERMISSION_SET特殊使用才需要設定為UNSAFE (注意程式是否有Console) Use  DBName  Create ASSEMBLY AssemblyName FROM ' c:\ FunName .dll ' WITH PERMISSION_SET = SAFE GO --建立函數Create Function CREATE FU...

[JQuery] Checkbox & Select (ddl) 用Name取Array

[Html] @foreach (var item in Model.QueryList) {     <input type="checkbox" name="chklist" value="@item.Id" />     <select name="ddllist">         <option value="@item.Id">@item.Id</option>    </select> } <script> //1,2,3 -- type:string[]  var chkvalues = $("input[name$='chklist']:checked").map(function () {                 return this.value;             }).get(); //1,2,3 -- type:string[]  var ddlValues = $("select[name=ddllist]").map(function () {                 return this.value;             }).get(); </script>

[HTML/MVC] 連動 Dropdownlist 後端->View

[.CS]             var result = new SelectList(new[]             {                 new { Id = "A", Name = "Code A" },                 new { Id = "B", Name = "Code B" },                 new { Id = "C", Name = "Code C" },             }, "Id", "Name");             ViewBag.DDLData = result; [HTML]           <select name="ddlT" id="ddlID">                   @foreach (var item in (SelectList)ViewBag.DDLData)           {             <option value="@item.Value" >@item.Text</option>           }         </select>        <sele...

[ASP.NET] Entity Framework 回滾事件

            try             {                 using (TransactionScope ts = new TransactionScope())                 {                     //執行的程式碼                     ts.Complete();                 }                             }             catch (Exception ex)             {                 throw;             } http://www.jiniannet.com/Article/I11409120400347

[MVC] ASP.NET MVC 專案加上 API 說明頁面

新增 Empty 專案,參考勾選 MVC 和 Web API  加入 具有讀取/寫入動作的 Web API 控制器 瀏覽網頁http://localhost:xxx/api/Get 會因為不同瀏覽器顯示不同格式,修改  App_Start\WebApiConfig.cs ,加入以下這一行,讓 ASP.NET Web API 永遠只回應 JSON 格式 GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();  在每個 function 增加描述 ,打 /// 會自動產生 <summary> 產生專案的XML文件  「專案屬性」→ 「建置」→  勾選「XML 文件檔案」,路徑改  「 App_Data\XmlDocument.XML 」 →  建置專案就會自動在 App_Data 目錄下產生 XmlDocument.XML 檔案 NuGet 安裝 Microsoft.AspNet.WebApi.HelpPage 套件 開啟 Areas/HelpPage/App_Start/HelpPageConfig.cs ,把以下程式碼註解取消 config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"))); 重點是確認路徑是否正確  "~/App_Data/XmlDocument.xml" 瀏覽 http://localhost:xxx/Help  參考連結 如何在 ASP.NET MVC 4 專案加上 Web API 與 API 說明頁面 進入 ASP .NET MVC 5 的世界 (台北場) 如何讓 ASP.NET Web API 無論任何要求都回應 JSON 格式

[MVC] Code First 避免DB資料遺失

利用Nuget安裝  Migrations Nuget套件管理員 -->  套件管理器主控台 下載套件,輸入指令: Enable-Migrations 增加 Migrations 資料夾及其檔案 修改  configuation.cs 修改 public Configuration() 如下圖  public Configuration()  {             AutomaticMigrationsEnabled = true;  //避免資料遺失             AutomaticMigrationDataLossAllowed = true; //避免SP遺失  } 更新DB時,可以下指令: Update-Database 參考網頁 Code First Migrations更新数据库结构(数据迁移)保证数据不丢失 [C# and EF] Tutorial: Entity Framework Code First Migrations 2/2

[C#] 匯出Excel

[ .CS ] #region 匯出Excel     public override void VerifyRenderingInServerForm(Control control)     {         //處理'GridView' 的控制項 'GridView' 必須置於有 runat=server 的表單標記之中     }     protected void btnExcel_Click(object sender, EventArgs e)     {         gvw_Execl.Visible = true;         Response.Clear();         Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("Lettrt.xls"));         Response.ContentType = "application/vnd.ms-excel";         Response.Charset = "";         Response.Write("<style type=text/css>");         Response.Write("td{mso-number-format:\"\\@\";}"); //將所有欄位格式改為"文字"         Response.Write("</style>");         //關閉ViewState         Enabl...