C# .NET - get all data of particular id from excel sheet

Asked By Shaku R on 08-May-12 03:00 AM
In excel sheet i have more column data for particular id
using oledb i wanted to get all details of that particular id using oledb.
id=1having 3 column A, B,C
each A,B,C having 5 rows

how to get it

Pat Hartman replied to Shaku R on 10-May-12 03:28 PM
Create a query that selects the columns you want.  If you want all rows, you won't need a where clause.  If you want to limit the rows, you will need a where clause.
Jitendra Faye replied to Shaku R on 15-May-12 10:17 AM
For this you can include where condition in query, use this code-

protected void btnGet_Click(object sender, EventArgs e)
String strConnection = "Data Source=MySystem;Initial Catalog=MySamplesDB;Integrated Security=True";

//file upload path
string path = fileuploadExcel.PostedFile.FileName;

//Create connection string to Excel work book
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;Persist Security Info=False";

//Create Connection to Excel work book
OleDbConnection excelConnection =new OleDbConnection(excelConnectionString);

//Create OleDbCommand to fetch data from Excel
OleDbCommand cmd = new OleDbCommand("Select [ID],[Name],[Designation] from [Sheet1$] Where [ID]='" + PassValue + "' ",excelConnection);

OleDbDataReader dReader;
dReader = cmd.ExecuteReader();


Try this code and let me know.