google-code-prettify

顯示具有 Asp.Net 程式開發 標籤的文章。 顯示所有文章
顯示具有 Asp.Net 程式開發 標籤的文章。 顯示所有文章

星期一, 3月 30, 2015

[EF] 如何用 Entity Framework 給 Date 欄位 Default Date

口白:
流動的水沒有形狀,漂流的風找不到蹤跡,任何案件的 Coding 都取決於心
唯一看透真相的是,外表看似卜朧共,智慧卻低於常人的 名卜朧共 刻爛
(謎之音:把 Code 刻到爛簡稱刻爛.爛..爛...)
Music:
#表升半音 []表高八度
4 3 2 6 4 2 3 #6 6 5 4 5 4 5 6 4 3 2 5 4 3 4 2 6 4 5 [2] [1] #6 6 5 6
4 3 2 6 4 2 3 #6 6 5 4 5 4 5 6 4 3 2 4 3 2 4 2 6 4 5 [2] #6 6 5 6
口白:
刻爛:真実はいつも一つ!

1. 打開 edmx (用 ADO.NET 實體資料模型設計工具打開)
2. 選擇你的 DateTime 欄位
3. 到屬性視窗,並改變 StoreGeneratedPattern 屬性值,從 None 改成 Computed

記得要把資料庫中的欄位定義預設值喔!

參考文獻:stackoverflow blog(code-first)

星期一, 9月 05, 2011

【VB】利用 Array.Indexof() 於陣列的字串變數中 的搜尋 對應字串於陣列中的 Index 位置

當 定義一組 矩陣變數 為字串 時,
如何於字串變數中,找到對應的字串位於 矩陣變數中的 Index 值?
可以利用 Array.Indexof() 來搜尋

Array.IndexOf 方法 (Array, Object, Int32)

範例如下:
Dim AttStr() As String = { "aaa", "bbb", "ccc", "abc" }
Dim FindStr As String = ""
Dim FindIndex As Integer

FindStr = "aaa"
FindIndex = Array.IndexOf(FindStr, Str2)
FindIndex = Array.IndexOf(AttStr,FindStr)
' Console.WriteLine(FindIndex) 'Print Output: 0

FindStr = "a"
FindIndex = Array.IndexOf(FindStr, Str2)
FindIndex = Array.IndexOf(AttStr,FindStr)
' Console.WriteLine(FindIndex) 'Print Output: -1

FindStr = "ccc"
FindIndex = Array.IndexOf(FindStr, Str2)
FindIndex = Array.IndexOf(AttStr,FindStr)
' Console.WriteLine(FindIndex) 'Print Output: 2

參考:
MSDN
[入門文章] .NET 陣列詳論

星期五, 4月 22, 2011

List、Array 轉String

宣告一個 List 變數 ArrList
Dim ArrList As New List(Of String)


用 ArrList.Add() 函數可把資料加入 List 中
ArrList.Add("a")
ArrList.Add("b")

'轉陣列
1. 將 ArrList 轉成 String() 陣列
Dim ArrString As String() 
ArrString = ArrList.ToArray
2. 將 ArrList 轉成 String 陣列
Dim ArrString() As String 
ArrString = ArrList.ToArray

'將 List 轉成 String 分隔符號用逗點分隔
'String.Join(",", ArrList.ToArray)

轉成 String ,內容為 "a,b"
方法1. 直接將 ArrList 轉成字串
Dim sstr As String = String.Join(",", ArrList.ToArray)
方法2 將 arrstring 陣列轉成字串
Dim sstr As String = String.Join(",", arrstring)

使用函數
ToArray()
 String.Join()

使用宣告變數
List(of String)
String()
String

星期四, 4月 21, 2011

【ASP.NET】利用 Sqldatasource 抓出 Gridview 的 SelectedDataKey

當 Gridview 設定了多個 DataKey 時
Sqldatasource 要如何取得 Selected DataKeys 中的某一個 DataKey
主要是用 ControlParameter 然後定義 PropertyNameSelectedDataKey 加上維度即可做到

<asp:ControlParameter ControlID="GridView1" Name="ServiceID" PropertyName="SelectedDataKey[0]" />




---------------------------------------------------------------------------------------------------------------------------
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
SelectCommand="SELECT A,B,C FROM Table WHERE A = @A And B=@B">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="A" PropertyName="SelectedDataKey[0]" />
<asp:ControlParameter ControlID="GridView1" Name="B" PropertyName="SelectedDataKey[1]" />
</SelectParameters>
</asp:SqlDataSource>
----------------------------------------------------------------------------------------------------------------------------