/// <summary> /// Produces a HTML table string from a <see cref="System.Data.SqlClient.SqlCommand"/> /// </summary> /// <param name="commandText"> /// The text of the SQL command. /// </param> /// <param name="connectionString"> /// A connection string. /// </param> public static string ToHtmlTable(string commandText, string connectionString) { using (var connection = new System.Data.SqlClient.SqlConnection(connectionString)) { var selectFromTableCommand = new System.Data.SqlClient.SqlCommand(commandText, connection); selectFromTableCommand.Connection.Open(); using (var reader = selectFromTableCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)) { try { var dataTable = new System.Data.DataTable(); dataTable.Load(reader); return(dataTable.ToHtmlTable()); } finally { selectFromTableCommand.Cancel(); } } } }