Currently, I am fetching data from particular sheet where it matched a "Key" value - But now I want to access data from all sheets where it matches "Key" value
Now in LogInUserData
| Key | Password | RememberMe | |
| LogInSuccessfully | [email protected] | a | 0 |
| LogInWithWrongEmail | a.a | a | 0 |
| LogInWithWrongPass | [email protected] | b | 0 |
And in Sheet2
| Key | Klarna |
| LogInSuccessfully | Demo |
And in Sheet2
KeyKlarna
LogInSuccessfullyDemo
Now, I want to access values of Key "Loginsuccessfully" from both the sheets - I have code but that fetches it from only first sheet and not from other - so how do i access complex data sheet from excel
I'm using ODBC Connection
- public static string TestDataFileConnection(string fileName)
- {
- string Filename = "C:\\Users\\PalakS\\source\\repos\\Daily update\\UnitTestProject2 - 10-04\\UnitTestProject2\\ExcelData\\LogInPageData.xlsx";
- string connectionString = string.Format("Dsn=Excel Files;READONLY=false;DBQ={0};", Filename);
- System.Data.Odbc.OdbcCommand odbcCmd = new System.Data.Odbc.OdbcCommand("", new System.Data.Odbc.OdbcConnection(connectionString));
- return connectionString;
- }
- public static T GetTestData
( string fileName, string sheet, string keyName) - {
- using (var connection = new OdbcConnection(TestDataFileConnection(fileName)))
- {
- connection.Open();
- var query = string.Format("select * from [{0}$]where key = '{1}'", sheet, keyName);
- var value = connection.Query
(query).FirstOrDefault(); - connection.Close();
- return value;
- }
- }
Function call:
- LogInUserModel user = AccessExcelData.GetTestData
("LogInPageData.xlsx", "LogInUserData", "LogInSuccessfully"); - string email = user.Email.ToString();
Sai Kumar KoonaPosted May 10, 2020, 9:12 AM
Alex LonyayPosted Jun 10, 2020, 7:22 AM
Alex LonyayPosted Jun 10, 2020, 7:21 AM
Now my function is this to fetch data:
public static T GetAllTestData(string keyName)
This function seems to be having an issue - I want to fetch all the data from all the tabs having unique key value, currently my value variable keeps getting override with latest value so at the end I'm not geting all the values from all the tabs
Is there a way to handle such case or some other approach I should try on handling data driven with multiple tabs in c#