Sends the System.Data.SqlClient.SqlCommand.CommandText to the System.Data.SqlClient.SqlCommand.Connection, and builds a System.Data.DataTable.
[Visual Basic] Shared OverloadsPublic Function ExecuteDataTable( _ ByVal connection As SqlConnection, _ ByVal commandText As String _ ) As DataTable [C#] public static DataTable ExecuteDataTable( SqlConnection connection, string commandText ); [C++] public: static DataTable* ExecuteDataTable( SqlConnection* connection, String* commandText ); [JScript] public static function ExecuteDataTable( SqlConnection connection, String commandText ): DataTable;
A representation of one table of in-memory data.
Use the ExecuteDataTable method to retrieve a System.Data.DataTable from a database. This requires less code than using the SqlDataAdapter.Fill method, performing the operations necessary to generate the table of in-memory data returned by a SqlDataAdapter.
[C#, Visual Basic] The following example creates a SqlDataAdapter and then executes it using the Fill method. The example is passed a string that is a Transact-SQL statement that returns an aggregate result.
[C#]SqlConnection connection = new SqlConnection("Server=127.0.0.1;Database=Northwind;Uid=sa;Pwd=;"); DataTable customers = DatabaseUtility.ExecuteDataTable(connection, "SELECT * FROM Customers");[Visual Basic]Dim connection As New SqlConnection("Server=127.0.0.1;Database=Northwind;Uid=sa;Pwd=;") Dim customers As DataTable = DatabaseUtility.ExecuteDataTable(connection, "SELECT * FROM Customers")
DatabaseUtility Class | Joel.Net Namespace | DatabaseUtility.ExecuteDataTable Overload List