2015年10月27日 星期二

[Android]利用LayoutInflater動態添加View

http://blog.csdn.net/guolin_blog/article/details/12921889

[C#] DataTable 實現SQL Distinct


DataTable BoardbyMenu = MyDataTable.DefaultView.ToTable(true, "Menu_ID");


來看一下 ToTable的參數:

ToTable ( bool distinct , params string[] columnNames ) ;

第一個true 過濾重複資料

第二個是欄位名稱,可放多個欄位 寫法:

new string[] { "Menu_ID , name" }




2015年10月15日 星期四

[Jquery]Ajax表單POST 多次

Ajax表單無故POST 兩次 , 弄了好久...

 發現罪魁禍首 是這隻.js jquery.unobtrusive-ajax

因為included 2 次 所以也POST 2 次

參考這篇

2015年10月12日 星期一

[C#][MVC] 資料寫進DB時,檢查是否有Null

create 是要準被塞進DB裡的物件 當create裡面屬性有 null 時 , 就給空值 , 防止DBNull 錯誤發生
  1. IList properties = typeof(ProductSize).GetProperties().ToList();
  2. foreach (var p in properties)
  3. {
  4. if (p.GetValue(create) == null && p.PropertyType == typeof(string))
  5. {
  6. p.SetValue(create, "");
  7. }
  8. }

2015年10月5日 星期一

[C#]MVC 關於刪除資料RemoveRange Remove

  1. var PTryReport = db.ProductTryReport.Where(x => x.ProductSize_ID == Check.ID);
  2. if (PTryReport.Any())
  3. {
  4. //原本這樣寫 會出錯交易失敗錯誤
  5. //因為刪除del就會改變PTryReport的值
  6. foreach (var del in PTryReport)
  7. {
  8. db.ProductTryReport.Remove(del);
  9. db.SaveChanges();
  10. }
  11. }
  12. //理想的寫法 用 RemoveRange 一次刪除全部資料
  13. if (PTryReport.Any())
  14. {
  15. db.ProductTryReport.RemoveRange(PTryReport);
  16. db.SaveChanges();
  17. }