protected static String connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +"Data Source=" + "C:\\sharedsupport.xls;" +"Extended Properties=Excel 8.0;"; ////"Select * from [" + DropDownList1.SelectedValue + "$A5:I" + rowNum + "]" //public Product findValue(Product item, DataTable table, ArrayList fieldList){var query = from r in table.AsEnumerable()where r.Field<String>("Product Part Number") == item.nameselect new{family = r.Field<Object>(fieldList[0].ToString())};foreach (var q in query){retun new Product() {family = q.family.ToString()};}return item;} //public DataTable getQueryTable(String cmd){OleDbConnection conn = new OleDbConnection(connectionString);conn.Open();OleDbCommand dbCommand = new OleDbCommand(cmd, conn);OleDbDataAdapter adapter = new OleDbDataAdapter();adapter.SelectCommand = dbCommand;DataSet dataSet = new DataSet();adapter.Fill(dataSet);conn.Close();return dataSet.Tables[0];}
Thursday, April 28, 2011
C#: Read and Query Data from Excel File
The following code will show a simple example which reads and queries data in the file.
Labels:
.Net
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment