~工作簡化,不再是難事~

2016-06-14

〔ASP.NET〕利用按鈕Command呼叫特定程式 / CommandName&CommandArgument Code Behind OnClick

不管是Button or LinkButton...皆有CommandName & CommandArgument屬性,可產生各別Click事件去傳遞值
若同一頁面上之Button皆有相同的行為,則可設定其OnCommand屬性來連結後端觸發事件,並利用CommandName & CommandArgument來傳遞設定值

例如:
前端程式碼
<asp: LinkButton ID ="lkb01" runat ="server" OnCommand ="FuncGo" CommandName="R1_001"></asp :LinkButton>


後端程式碼
Protected Sub FuncGo(sender As Object, e As CommandEventArgs)
    Select Case e.CommandName
        Case "R1_001"
            'do somthing
        Case Else
    End Select

End Sub
Read More

〔ASP.NET〕Page事件發生先後順序 / Page.Load,Master.Load

  • ●一般情況下:

Page.PreInit
Page.Init
Page.InitComplete
Page.PreLoad 
Page.Load 
控制項事件(例如:Button.Click、TextBox.TextChanged...)
Page.LoadComplete 
Page.PreRender 
Page.PreRenderComplete
Page.Render
Page.Unload


  • ●使用了 MasterPage 情況, MasterPage 與 ContentPage 事件順序:


ContentPage.PreInit
Master.Init 
ContentPage.Init
ContentPage.InitComplete
ContentPage.PreLoad
ContentPage.Load Master.Load 
ContentPage.LoadComplete
ContentPage.PreRender
Master.PreRender 
ContentPage.PreRenderComplete

Read More

2016-06-07

〔VBA〕 取得Excel選取的範圍列(不需連續) / Seletion.Areas Rows

範例:依據目前工作表所選取的範圍,顯示所有列號

Private Sub PrintTSF(ByVal savePath As String)
    Dim FB As Workbook: Set FB = ActiveWorkbook     '目前活頁簿
    Dim FS As Worksheet: Set FS = ActiveSheet            '目前工作表

    Dim xArea As Range
    Dim i As Integer
    Dim iRow As Integer
    With FS
        For Each xArea In Selection.Areas
            For i = 1 To xArea.Rows.Count
                iRow = xArea.Rows(i).Row            '一筆筆取得選取的列號
                MsgBox iRow
            Next
        Next xArea
    End With
    Set FB = Nothing
    Set FS = Nothing

End Sub
Read More

2016-06-06

〔SQL〕UPDATE SELECT 利用SELECT做大量更新

範例:將訂單表身(OD00D1)出貨日,批次更新為訂單表頭(OD00H)出貨日


UPDATE
    OD00D1
SET
    OD00D1. DeliveryDate = OD00H. DeliveryDate,
    OD00D1. ProductDate = DATEADD( Day,-7 ,OD00H. DeliveryDate)
FROM
    OD00D1
    INNER JOIN OD00H
        ON OD00D1 .ODNo = OD00H .ODNo
WHERE

    OD00D1. ODNo = 'OD1606-00002'
Read More

〔SQL〕一次取得資料庫欄位名稱、型態等設定 / Select Table Column Type

範例:列出資料庫內所有資料表及其欄位名稱等相關設定


SELECT 
    a.TABLE_NAME                 as 表格名稱 , 
    b.COLUMN_NAME                as 欄位名稱 , 
    b.DATA_TYPE                  as 資料型別 , 
    b.CHARACTER_MAXIMUM_LENGTH   as 最大長度, 
    b.COLUMN_DEFAULT             as 預設值 , 
    b.IS_NULLABLE                as 允許空值 , 
    ( 
        SELECT 
            value 
        FROM 
            fn_listextendedproperty (NULL, 'schema', 'dbo', 'table',   
                                     a.TABLE_NAME , 'column' , default ) 
        WHERE 
            name='MS_Description'   
            and objtype ='COLUMN'  
            and objname Collate Chinese_Taiwan_Stroke_CI_AS=b .COLUMN_NAME 
    ) as 欄位備註 
FROM 
    INFORMATION_SCHEMA.TABLES   a 
    LEFT JOIN INFORMATION_SCHEMA. COLUMNS b ON ( a.TABLE_NAME =b. TABLE_NAME) 
WHERE 
    TABLE_TYPE='BASE TABLE'  
ORDER BY  

    a.TABLE_NAME , ordinal_position   
Read More

2016-06-04

〔ASP.NET〕Convert sqlDataReader to DataTable / 將DataReader資料轉入DataTable

Dim dt As New DataTable
dt.Load(dr)        




範例:
        Dim Conn As SqlConnection = DBLink .setConn("ConnectionString" )
        Dim strSQL As String = ""
        Dim cmd As SqlCommand = Nothing
        Dim dr As SqlDataReader = Nothing
        Try
           
             strSQL = "SELECT * FROM Table"

            cmd = New SqlCommand(strSQL, Conn)
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                Dim dt As New DataTable
                dt.Load(dr)
                Return dt
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        Finally
            PublicFunction.iniDispose(cmd, dr, Conn)

        End Try
Read More

Popular Posts

Copyright © 2016 Scenic's BOX. 技術提供:Blogger.