This situation is confronted by each qa individual in automation testing providers firm whereas creating framework. If we’re making a DataDriven Framework we have to cross knowledge from file, This may be performed in two methods in C#:
-
Utilizing libraries like “Excellibrary” in NugetPackage supervisor of Visible studio by which we are able to learn and write knowledge from Excel and csv recordsdata.
-
Utilizing Oledb instructions : We’d like set up the corresponding driver like “Microsoft Jet OLEDB Driver 4.0”, and create connection object for the Excel. Right here you may question utilizing sql instructions the place your excel file acts as Database.
Consult with beneath code:
// Connection String for Excel 2007 Format (.XLSX)
“Supplier=Microsoft.ACE.OLEDB.12.0;Knowledge Supply=C:Book1.xlsx;Prolonged Properties=”Excel 8.0;HDR=Sure””
// set up connection:
String strExcelConn = “Supplier=Microsoft.Jet.OLEDB.4.0;”
“Knowledge Supply=Book1.xls;”
“Prolonged Properties=”Excel 8.0;HDR=Sure””;
OleDbConnection connExcel = new OleDbConnection(strExcelConn);
OleDbCommand cmdExcel = new OleDbCommand();
cmdExcel.Connection = connExcel;
// Entry sheets
connExcel.Open();
DataTable dtExcelSchema;
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
connExcel.Shut();
//It will give the identify of the primary sheet. i.e. Sheet1$
//Working a Choose Question by Specifying Column Names like beneath:
DataSet ds = new DataSet();
string SheetName = dtExcelSchema.Rows[0][“TABLE_NAME”].ToString();
cmdExcel.CommandText = “SELECT ID, Identify From [” + SheetName + “]”;
da.SelectCommand = cmdExcel;
da.Fill(ds);