2014年11月21日 星期五

[C#] Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.


form: http://ianworkshop.blogspot.tw/2014/01/validation-failed-for-one-or-more.html


可能某個不可為null的欄位, 填入了null, 但是不知道是哪個欄位, 因此使用try catch來捕抓錯誤

            try
            {
                _db.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }

[C#] Nullable 說明

form: http://www.dotblogs.com.tw/dotjum/archive/2008/08/02/4756.aspx



Nullable 是 .NET 2.0 所新增的類別,

主要可以用來針對 實值型別 (參考一) 給予 Null 當初始值 及 檢查是否為 null ,

這邊先瞭解關於常見 實值型別  型別有哪些,而 DateTime 在.NET Framework 實值型別(參考二)

而之前自己的經驗,在對 inet , Datetime 做處理是 null 的時候,

以 DateTime 來說會使用 DateTime.MinValue 的方式,來代表一個 Null 的值,

也聽別人的經驗說,就大家說好一個某一個日期就是null的值(但這樣非常不好,請大家不要這樣)

而使用Nullable就能方便處理實值型別初始值 的問題

Nullable 的使用也很簡單

Nullable<型別> 變數名 = null ;或   型別? 變數 = null;




2014年10月7日 星期二

[C#] 列凍結 Frozen


        private void Form1_Load(object sender, EventArgs e)
        {
            DataTable table = GetTable();
            dataGridView1.DataSource = table;

            dataGridView1.Columns[0].Frozen = true;

        }

        /// <summary>
        /// This example method generates a DataTable.
        /// </summary>
        private DataTable GetTable()
        {
            // Here we create a DataTable with four columns.
            DataTable table = new DataTable();
            table.Columns.Add("Dosage", typeof(int));
            table.Columns.Add("Drug", typeof(string));
            table.Columns.Add("Patient", typeof(string));
            table.Columns.Add("Date", typeof(DateTime));

            for (int i = 0; i < 50; i++)
             {
                // Here we add five DataRows.
                table.Rows.Add(25 + i, "Indocin", "David", DateTime.Now);
                table.Rows.Add(50 + i, "Enebrel", "Sam", DateTime.Now);
                table.Rows.Add(10 + i, "Hydralazine", "Christoff", DateTime.Now);
                table.Rows.Add(21 + i, "Combivent", "Janet", DateTime.Now);
                table.Rows.Add(100 + i, "Dilantin", "Melanie", DateTime.Now);
            }

            return table;
        }





---------------------------






1) 列冻结
DataGridViewColumn.Frozen 属性为 true 时, 该列左侧的所有列被固定, 横向滚动时固定列不随滚动条滚动而左右移动。这对于重要列固定显示很有用。
示例代码1:
dataGridView1.Columns[0].Frozen = true;  //只锁定第1列
dataGridView1.AllowUserToOrderColumns = true; //更改栏位顺序
注意:
DataGridView.AllowUserToOrderColumns = True 时,固定列不能移动到非固定列, 反之亦然。
示例代码2:
DataGridView1.Columns[1].Frozen = true; // 锁定第1列和第2列
2) 行冻结
DataGridViewRow.Frozen 属性为 True 时, 该行上面的所有行被固定, 纵向滚动时固定行不随滚动条滚动而上下移动。
// DataGridView1 的上2行固定DataGridView1.Rows[2].Frozen = true;

http://www.phpbegin.com/2013/04/30/295.html





2014年9月30日 星期二

[Javascript]三個好用的Height,Width屬性





<script type="text/javascript">

//整個螢幕解析度
document.write("window.screen.height:" + window.screen.height + "<br/>");
document.write("window.screen.width:" + window.screen.width + "<br/>");

//扣掉視窗下面那個工作列
document.write("window.screen.availHeight:" + window.screen.availHeight + "<br/>");
document.write("window.screen.availWidth:" + window.screen.availWidth + "<br/>");

//扣掉視窗下面那個工作列 與瀏覽器工具列和邊框
document.write("document.documentElement.clientHeight:" + document.documentElement.clientHeight + "<br/>");
document.write("document.documentElement.clientWidth:" + document.documentElement.clientWidth + "<br/>");

</script>



From: http://www.dotblogs.com.tw/puma/archive/2009/04/02/javascript-width-height-clientwidth-availwidth-screen.aspx

2014年8月13日 星期三

[SQL] 小心使用With NoLock



FROM: http://www.dotblogs.com.tw/ricochen/archive/2011/04/15/22758.aspx


擷自某段文字

當你使用NoLock時,你等於是告訴SQL Server 使用者不在意資料正確性和一致性,
假設某位使用者正在更新資料表,就會影響其他使用者查詢(with nolock)該資料的正確性和一致性,
那些查詢的使用者可能會遇到重複讀取相同資料、遺漏讀取或中途讀取..等狀況,
而我更在意頁面分割的動作
(頁面分割這裡不多敘述,但你可以參考2011年4月 RUN!PC我所發表的索引概念和設計)
我只和你說頁面分割是相當耗費系統資源的動作,
你絕對不希望使用者再查詢資料時,還得同時處理頁面分割動作,
所以無論如何請一定要減少頁面分割發生的頻率。





2014年8月2日 星期六

輸入法消失及無法切換解決方式



from: http://goo.gl/9OKeS

輸入法不見了,不論怎麼切換都沒有用

 【控制台】→【地區及語言】也設定好了
但就是不出現
看來這是個辣手的問題

提供以下解決方式參考一下:

1. 點選【開始功能表】,在【搜尋程式及檔案】輸入框中輸入"regedit",按下【Enter】,進入登錄編輯程式
regedit.jpg



2. 找到 "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",此行是在開機的時候應該自動執行的程式清單,看看右邊的欄位有無ctfmon字串值,若沒有出現Ctfmon,則右邊欄位點按【右鍵】新增【字串值】"Ctfmon",然後再修改這個字串值的數值資料為 "C:\Windows\system32\ctfmon.exe" 完成後關閉
regeditrun.jpg



3.重開機(或登出再登入),語言列應該就可以成功出現了





如果到此問題已解決,那恭喜你
但我的同事就沒那麼幸運了,語言列出現了,但

無法切換輸入法

【控制台】→【地區及語言】也設定好了
但就是不出現
看來這個辣手的問題

提供以下解決方式參考一下:

1. 點選【開始功能表】,在【搜尋程式及檔案】輸入框中輸入"regedit",按下【Enter】,進入登錄編輯程式

2.找到"HKEY_CURRENT_USER\Keyboard Layout\Toggle"裡的"Language Hotkey",將數值改成 1,完成後關閉

3.重開機(或登出再登入),語言列應該就可以成功出現了

2014年7月15日 星期二

[.NET ASP] 根治錯誤

from : http://blog.csdn.net/nileel/article/details/3519744


編譯完項目,訪問,經常出現“配置錯誤”,行***<add assembly="*"/>,某“DLL”文件拒绝访问。重启IIS也不行,重新编译也不对,基本每天都能遇到,频繁的时候编译一次遇到一次。狠狠的百度了一番,终于明白了。原来是windows的索引服务在搞鬼。windows的索引服务对asp.net的临时目录编制索引时,锁定了临时文件的访问权限,因此报错!
知道了原因,就好辦了

最簡單的解決辦法就是禁用索引服務,但是影響比較大。
可以刪除的PDB文件,但是調試的時候不方便
最後我採用的解決辦法是:
配置ASP.net的臨時目錄不受索引服務服務的影響的步驟如下:

1,開始 - 管理工具 - 計算機管理(Win2003的的位置,其他操作系統類似)打開計算機管理
2、展开计算机管理左边树中“服务和应用程序”节点,再在其下展开“索引服务”节点,再在其下展开“System”节点,再在其下展开“目录”节点。
3,在計算機管理的右邊我們可以看到配置的索引服務目錄。
4,在“目錄”節點上右擊鼠標,選擇“新建” - “目錄”
5,在“添加目錄”對話框中,路經輸入框中輸入ASP.net的臨時文件目錄默認應該是:
C :/ WINDOWS/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files文件/
6,在“包含在索引中嗎?”選項中,選擇“否”
7,單擊“確定”按鈕
8,在“索引服務”節點上右鍵單擊,重起索引服務即可。



















2014年7月7日 星期一

[C#] 如何取得 Request URL 的各個部分


from寶哥  http://blog.miniasp.com/post/2008/02/10/How-Do-I-Get-Paths-and-URL-fragments-from-the-HttpRequest-object.aspx


底下這張表就是各種跟 Browser Request 的網址相關的屬性與用法:


網址:http://localhost:1897/News/Press/Content.aspx/123?id=1#toc
Request.ApplicationPath/
Request.PhysicalPathD:\Projects\Solution\web\News\Press\Content.aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath)D:\Projects\Solution\web\News\Press
Request.PhysicalApplicationPathD:\Projects\Solution\web\
System.IO.Path.GetFileName(Request.PhysicalPath)Content.aspx
Request.CurrentExecutionFilePath/News/Press/Content.aspx
Request.FilePath/News/Press/Content.aspx
Request.Path/News/Press/Content.aspx/123
Request.RawUrl/News/Press/Content.aspx/123?id=1
Request.Url.AbsolutePath/News/Press/Content.aspx/123
Request.Url.AbsoluteUrihttp://localhost:1897/News/Press/Content.aspx/123?id=1
Request.Url.Schemehttp
Request.Url.Hostlocalhost
Request.Url.Port1897
Request.Url.Authoritylocalhost:1897
Request.Url.LocalPath/News/Press/Content.aspx/123
Request.PathInfo/123
Request.Url.PathAndQuery/News/Press/Content.aspx/123?id=1
Request.Url.Query?id=1
Request.Url.Fragment 
Request.Url.Segments/
News/
Press/
Content.aspx/
123






[SQL] NOT IN clause and NULL values


from:http://stackoverflow.com/questions/129077/not-in-clause-and-null-values


當下NOT IN時,括號裡面的值含有NULL,就會甚麼都撈不到

因為null不等於任何值

null也不等於null

所以,下NOT IN時,建議將null過濾掉 WHERE *** IS NOT NULL


A: select 'true' where 3 in (1, 2, 3, null)
B: select 'true' where 3 not in (1, 2, null)


Query A is the same as:
select 'true' where 3 = 1 or 3 = 2 or 3 = 3 or 3 = null
Since 3 = 3 is true, you get a result.
Query B is the same as:
select 'true' where 3 <> 1 and 3 <> 2 and 3 <> null
When ansi_nulls is on, 3 <> null is UNKNOWN, so the predicate evaluates to UNKNOWN, and you don't get any rows.
When ansi_nulls is off, 3 <> null is true, so the predicate evaluates to true, and you get a row.
zh-CN → zh-TW
,下

2014年7月6日 星期日

[C#] KeyValue 代碼表

from: http://www.cnblogs.com/manongxiaobing/archive/2012/11/05/2755412.html



  鍵盤按鍵 - 對應的代碼
backspace8
tab9
enter13
shift16
ctrl17
alt18
pause/break19
caps lock20
escape27
page up33
Space32
page down34
end35
home36
arrow left37
arrow up38
arrow right39
arrow down40
insert45
delete46
048
149
250
351
452
553
654
755
856
957
a65
b66
c67
d68
e69
f70
g71
h72
i73
j74
k75
l76
m77
n78
o79
p80
q81
r82
s83
t84
u85
v86
w87
x88
y89
z90
left window key91
right window key92
select key93
numpad 096
numpad 197
numpad 298
numpad 399
numpad 4100
numpad 5101
numpad 6102
numpad 7103
numpad 8104
numpad 9105
multiply106
add107
subtract109
decimal point110
divide111
f1112
f2113
f3114
f4115
f5116
f6117
f7118
f8119
f9120
f10121
f1










 

MangoHost Copyright © 2009 Cookiez is Designed by Ipietoon for Free Blogger Template