The following code returns data from a spreadsheet into a grid perfectly
[
string excelConnectString = "Provider = Microsoft.Jet.OLEDB.4.0;" +
"Data Source = " + excelFileName + ";" +
"Extended Properties = Excel 8.0;";
OleDbConnection objConn = new OleDbConnection(excelConnectString);
OleDbCommand objCmd = new OleDbCommand("Select * From [Accounts$]", objConn);
OleDbDataAdapter objDatAdap = new OleDbDataAdapter();
objDatAdap.SelectCommand = objCmd;
DataSet ds = new DataSet();
objDatAdap.Fill(ds);
fpDataSet_Sheet1.DataSource = ds;//fill a grid with data
]
The spreadsheet I'm using has columns named from A and so on( just standard column names ) and the sheet name is Accounts.
I have a problem with the query ...
[OleDbCommand objCmd = new OleDbCommand("Select * From [Accounts$]", objConn);]
How can I make the query string like this...
"Select <columnA>,<columnB>,SUM<columnG> from [Accounts$] group by <columnA>,<columnB>"
..so that it returns the results of this query
Note : columnA is A on Sheet , columnB is B on Sheet and columnG is G on Sheet
Other possible Alternatives:
- I have the data of that excel spread into a DataTable object, how can I query the DataTAble object
- I read about a DataView object that it can take a table and return the table manipulated according to (
<dataviewObject>.RowFilter = "where..."
) , but I don't know how to use the query I want.