Dear developers,
I am trying to find the differences between Imported Excel File and gridView data imported from Oracle Database. I am trying to put the data into DataSet, so I can compare between them.
OracleDataImported v.s ImportedExcelFileData.
OracleDataImported Code:
- private static DataSet OracleDataImported()
- {
- String strConnString;
- strConnString = "DATA SOURCE=DatabaseName;USER ID=UserName;PASSWORD=123;";
- var conn = new OracleConnection(strConnString);
- String strSQL;
-
- OracleCommand cmd = conn.CreateCommand();
- strSQL = "select Name,Password from OUD.USERDATA";
- cmd = new OracleCommand(strSQL, conn);
- cmd.CommandType = CommandType.Text;
-
- OracleDataAdapter da = new OracleDataAdapter();
- da = new OracleDataAdapter(cmd);
- DataSet ds1 = new DataSet();
- da.Fill(ds1);
-
- return ds1;
- }
ImportedExcelFileData code:
- protected void ImportedExcelFileData(object sender, EventArgs e)
- {
-
- if ((FileUpload.HasFile))
- {
- if (!Convert.IsDBNull(FileUpload.PostedFile) &
- FileUpload.PostedFile.ContentLength > 0)
- {
-
- FileUpload.SaveAs(Server.MapPath(".") + "\\" + FileUpload.FileName);
-
-
- OleDbConnection myExcelConn = new OleDbConnection
- ("Provider=Microsoft.ACE.OLEDB.12.0; " +
- "Data Source=" + Server.MapPath(".") + "\\" + FileUpload.FileName +
- ";Extended Properties=Excel 12.0;");
- try
- {
- myExcelConn.Open();
-
-
-
-
- OleDbDataAdapter oleDbDataAdapter;
- oleDbDataAdapter = new OleDbDataAdapter("select rtrim(ltrim(name)) as [Name],rtrim(ltrim(password)) as [Password] from [Sheet1$]", myExcelConn);
- oleDbDataAdapter.TableMappings.Add("Table", "ExcelTable");
- DataSet dataSet = new DataSet();
- oleDbDataAdapter.Fill(dataSet);
-
-
- DisplayExcelData.DataSource = dataSet;
- DisplayExcelData.DataBind();
-
- lblConfirm.Text = "DATA IMPORTED TO THE GRID, SUCCESSFULLY.";
- lblConfirm.Attributes.Add("style", "color:green");
- }
- catch (Exception ex)
- {
-
- lblConfirm.Text = ex.Message;
- lblConfirm.Attributes.Add("style", "color:red");
- }
- finally
- {
-
- myExcelConn.Close(); myExcelConn = null;
- }
- }
- }
- }
Button to find the differences code:
- protected void calculate(object sender, EventArgs e)
- {
-
- var ds = OracleDataImported();
-
- DisplayDBData.DataSource = ds;
- DisplayDBData.DataBind();
-
- DataSet dataSet;
-
- var oleDbConnection = ImportedExcelFileData(out dataSet);
- DisplayExcelData.DataSource = dataSet.Tables[0];
- DisplayExcelData.DataBind();
- oleDbConnection.Close();
-
-
- var dtAll = GetDataDifference(ds, dataSet);
- DisplayDifferenceData.DataSource = dtAll;
- DisplayDifferenceData.DataBind();
- }
How to do it?
Please, assist ..
Regards,