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
5 章老師的電腦小講堂: 〔ASP.NET〕Convert sqlDataReader to DataTable / 將DataReader資料轉入DataTable Dim   dt   As   New   DataTable dt.Load(dr)          範例:          Dim Conn As SqlConnection = DBLink .setConn( "Connection...
< >
小講堂經過多次搬移,舊文章連結及內容較難整理~
大家可以新文章為主~
每篇文章後有代碼,任何文章問題可至FB小講堂用代碼提問唷~