Hi ythisbug
Your query to return the ExecutionTime for each test case is:
select executiontime from TABLE_NAME where testcase = 'Test1'
You can then use the SqlDataReader Class to get the results of this query and add them together, something like:
string queryString ="select executiontime from TABLE_NAME where testcase = ";
string getTestCases = "select distinct TestCase from TABLE_NAME;";
using (SqlConnection connection = new SqlConnection(connectionString))
{
int iTotalTime = 0;
SqlCommand command =
new SqlCommand(getTestCases, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
queryString = queryString + reader[0] + ";";
command.CommandText = queryString;
SqlDataReader timereader = command.ExecuteReader();
while(timereader.Read())
{
iTotalTime = iTotalTime + (int)timereader[0];
}
}
}
The question is how are you populating the grid? Are you binding directly to an SQL query? Or are you building up the grid yourself?
So you could select distinct from the Table to get a distinct list of TestCases and then use those in a loop to get the totalExecution times for each test case. Then you can create a list of testcases and execution times and use that list to populate the grid.
What I suggest is to use a DataSource to populate your grid. So create an object that will contain the data you are interested in eg:
class TestResults
{
public String Test_Name { get; set; }
public int Test_Execution_Time { get; set; }
}
Then you can use this to hold the results from the query.
list<TestResults> testResultsList = new List<TestResults>();
TestResults tRes = new TestResult();
tRes.Test_Name = reader[0];
tRes.Test_Execution_Time = iTotalTime;
testResultsList.Add(tRes);
dataGridView1.DataSource = testResultsList;