I need to get loaded data from excel to textboxes,
I know how to get it viewed in gridview, but I need to get a specific cell value to be captured to a text box.
Example: TextBox FirstName should be captured from Cell A3 LastName should be captured from Cell A4.
Can anybody help to sort it easily?
Edited on 11/6/2013
I have tried below code and it's working but i have put separate reader to capture each text box value but it will capture only datas in first row can anyone help to read and capture from row and column difference cell values at once
string constrg = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Txtpath.Text + ";Extended Properties=Excel 12.0;"; OleDbConnection conns = new OleDbConnection(constrg);
OleDbDataReader dr;
try
{
conns.Open();
OleDbCommand cmd = new OleDbCommand("Select * From [Sheet1$A10:H18]", conns);
dr = cmd.ExecuteReader();
if (dr.HasRows == false)
{
throw new Exception();
}
if (dr.Read())
{
TxtCluster.Text = dr[2].ToString();
TxtPGroup.Text = dr[6].ToString();
}
OleDbCommand cmd1 = new OleDbCommand("Select * From [Sheet1$A11:H18]", conns);
dr = cmd1.ExecuteReader();
if (dr.HasRows == false)
{
throw new Exception();
}
if (dr.Read())
{
TxtJbsize.Text = dr[2].ToString();
TxtOsource.Text = dr[6].ToString();
}
OleDbCommand cmd2 = new OleDbCommand("Select * From [Sheet1$A12:H18]", conns);
dr = cmd2.ExecuteReader();
if (dr.HasRows == false)
{
throw new Exception();
}
if (dr.Read())
{
TxtNoPg.Text = dr[2].ToString();
TxtProject.Text = dr[6].ToString();
}