private DataTable GetExcelData(double strLat, double strLong)
{
DataTable dtDataFromExcel = new DataTable("dtDataFromExcel");
OleDbConnection oledbConn = new OleDbConnection();
try
{
oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
Application.StartupPath + @"\ExcelData\grided_wgn.xlsx; Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';");
if (oledbConn.State == ConnectionState.Closed)
{
oledbConn.Open();
}
OleDbCommand cmd = new OleDbCommand(); ;
DataSet ds = new DataSet(); ;
cmd.Connection = oledbConn;
OleDbDataAdapter adap = new OleDbDataAdapter("SELECT * FROM [IMD_1deg_wgn$]", oledbConn);
adap.Fill(ds, "dsSlno");
DataTable dtExcelData = ds.Tables["dsSlno"];
if (dtExcelData != null && dtExcelData.Rows.Count > 0)
{
var results = (from m in dtExcelData.AsEnumerable()
where m.Field<double>("WLATITUDE") == strLat
&& m.Field<double>("WLONGITUDE") == strLong
select m);
if (results != null && results.Count() > 0)
{
dtDataFromExcel = results.CopyToDataTable();
}
else
{
dtDataFromExcel = null;
}
}
}
catch (Exception ex)
{
LoggerClass.ErrorException(ex.Message, ex);
}
return dtDataFromExcel;
}
{
DataTable dtDataFromExcel = new DataTable("dtDataFromExcel");
OleDbConnection oledbConn = new OleDbConnection();
try
{
oledbConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
Application.StartupPath + @"\ExcelData\grided_wgn.xlsx; Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';");
if (oledbConn.State == ConnectionState.Closed)
{
oledbConn.Open();
}
OleDbCommand cmd = new OleDbCommand(); ;
DataSet ds = new DataSet(); ;
cmd.Connection = oledbConn;
OleDbDataAdapter adap = new OleDbDataAdapter("SELECT * FROM [IMD_1deg_wgn$]", oledbConn);
adap.Fill(ds, "dsSlno");
DataTable dtExcelData = ds.Tables["dsSlno"];
if (dtExcelData != null && dtExcelData.Rows.Count > 0)
{
var results = (from m in dtExcelData.AsEnumerable()
where m.Field<double>("WLATITUDE") == strLat
&& m.Field<double>("WLONGITUDE") == strLong
select m);
if (results != null && results.Count() > 0)
{
dtDataFromExcel = results.CopyToDataTable();
}
else
{
dtDataFromExcel = null;
}
}
}
catch (Exception ex)
{
LoggerClass.ErrorException(ex.Message, ex);
}
return dtDataFromExcel;
}
No comments:
Post a Comment