Create table from database query

protected Data.DataTable GetDataTableFromDatabase(string ConnectionString, string SelectString)
{
 Data.DataTable QueryResultsDataTable = new Data.DataTable();
 //To get the connection string:  Server Explorer... Data Connections... Select a .dbo database... Press F4... Copy connection string to the clipboard.
 System.Data.SqlClient.SqlDataAdapter DataAdapter = new System.Data.SqlClient.SqlDataAdapter(SelectString, ConnectionString);
 DataAdapter.SelectCommand.CommandTimeout = 100;
 DataAdapter.Fill(QueryResultsDataTable);
 return QueryResultsDataTable;
}

No comments:

Post a Comment