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 錯誤發生
IList properties = typeof(ProductSize).GetProperties().ToList();
  foreach (var p in properties)
  {
     if (p.GetValue(create) == null && p.PropertyType == typeof(string))
     {
         p.SetValue(create, "");
      }
  }

2015年10月5日 星期一

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

var PTryReport = db.ProductTryReport.Where(x => x.ProductSize_ID == Check.ID);
  if (PTryReport.Any())
  {
    //原本這樣寫 會出錯交易失敗錯誤
    //因為刪除del就會改變PTryReport的值
    foreach (var del in PTryReport)
    {
      db.ProductTryReport.Remove(del);
      db.SaveChanges();
    }
  }
//理想的寫法 用 RemoveRange 一次刪除全部資料
 if (PTryReport.Any())
 {
     db.ProductTryReport.RemoveRange(PTryReport);
     db.SaveChanges();
                                   
  }