Click or drag to resize

SqlHelperExecuteSqlCommand Method (String, String, IEnumerableString)

Framework to automate tests using Selenium WebDriver
Method is used for execution SQL query (select) and reading each column from row.

Namespace:  Ocaramba.Helpers
Assembly:  Ocaramba (in Ocaramba.dll) Version: 3.3.1
Syntax
C#
public static Dictionary<string, string> ExecuteSqlCommand(
	string command,
	string connectionString,
	IEnumerable<string> columns
)

Parameters

command
Type: SystemString
SQL query.
connectionString
Type: SystemString
Server, user, pass.
columns
Type: System.Collections.GenericIEnumerableString
Name of columns.

Return Value

Type: DictionaryString, String
Dictionary of each column existed in raw.
Exceptions
ExceptionCondition
KeyNotFoundExceptionException when there is not given column in results from SQL query.
Examples
How to use it:
var connectionString = "User ID=sqluser;Password=sqluserpassword;server=servername;";
ICollection<string> column = new List<string>();
column.Add("NationalIDNumber");
column.Add("ContactID");
const string SqlQuery = "SELECT [NationalIDNumber] as " + column.ElementAt(0) + " , [ContactID] as " + column.ElementAt(1) + " from [AdventureWorks].[HumanResources].[Employee] where EmployeeID=1";
Dictionary<string, string> results = SqlHelper.ExecuteSqlCommand(command, GetConnectionString(server), column);
See Also