Tips and tricks for .NET using ASP and VB code.

Create table from database query

    Protected Function GetDataTableFromDatabase(ConnectionString As String, SelectString As String) As Data.DataTable
        Dim QueryResultsDataTable As New Data.DataTable
        'To get the connection string:  Server Explorer... Data Connections... Select a .dbo database... Press F4... Copy connection string to the clipboard.
        Dim DataAdapter As New System.Data.SqlClient.SqlDataAdapter(SelectString, ConnectionString)
        DataAdapter.SelectCommand.CommandTimeout = 100
        DataAdapter.Fill(QueryResultsDataTable)
        Return QueryResultsDataTable
    End Function

No comments:

Post a Comment

Search This Blog