I am trying to access excel data from a file using windows form to input latitude and longitude information. However, When I debug it, it throws "input string not in correct format" error. I am using the following code:
namespace Excel_Access
{
public partial class Form1 : Form
{
string myDouble2;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string cellValue = "";
string cellValue1 = "";
string cellValue2 = "";
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source =G:\Manish Dixit\TAMU\BS2015\SolarInsolation\Excel Sheets\Clr_Index.xlsm; Extended Properties= Excel 12.0");
OleDbDataAdapter da = new OleDbDataAdapter("select*from[Sheet2$]", con);
DataTable dt = new DataTable();
da.Fill(dt);
int i = 1;
do
{
cellValue = dt.Rows[i][0].ToString();
if(double.Parse(cellValue)==double.Parse(textBox1.Text))
cellValue1 = dt.Rows[i][1].ToString();
if (double.Parse(cellValue1) == double.Parse(textBox2.Text))
{
cellValue2 = dt.Rows[i][5].ToString();
MessageBox.Show(cellValue2);
}
i++;
}
while (i < 441);
//myDouble2 = ExcelDB(10, "L2");
//MessageBox.Show("The value is " +myDouble2);
}
}
}
Could you please suggest why this is happening? The input values of latitude and longitude are in decimal.Please see the attached image of the data I am trying to access. See data image in Excel file here