ExecuteStatementWithResult
Darren Comeau edited this page Oct 14, 2018
·
1 revision
Will execute the SQL statement against the database. Any results will be returned in a DataSet object.
public DataSet ExecuteStatementWithResult(string sqlStatement);
Parameters
sqlStatement
String
The SQL statement you wish to execute against the database.
Returns
DataSet
One or more tables returned from the execution of the SQL statement.
Exceptions
StatementReturnedNoTables
After executing the statement, no datasets were returned. NB different from no rows being returned.
Select all the columns from a table so I can confirm it has the right number of columns
// Setup the Database Tester object using the MS SQL implementation
var connectionstring = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=tempdb;Integrated Security=SSPI;";
VulcanAnalytics.DBTester.DatabaseTester tester = new VulcanAnalytics.DBTester.MsSqlDatabaseTester(connectionstring);
// Parameters for ExecuteStatementWithResult
var sqlStatement = "SELECT * FROM [dbo].[testable] WHERE 1=0;";
// Call the ExecuteStatementWithResult method to execute the SQL statement and return the result set
var results = tester.ExecuteStatementWithResult(sqlStatement);
// use ExecuteStatementWithResult output
var tableOneColumnCount = results.Tables[0].Columns.Count;
Assert.AreEqual(5,tableOneColumnCount);