In our application, we are saving the Excel files uploaded by the users to the database with varBinary data type. But, we would also like to retrieve back the data and be able to parse it to get the data in it (columns, rows).
I already know how to read an Excel File into a DataTable to get the data from it(like the code below), but I don't know how to do it if the DataSource is of type varbinary.
// Getting data from actual Excel File
var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);
var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
var ds = new DataSet();
adapter.Fill(ds);
foreach (DataTable dt in ds.Tables) {
Response.Write(dt.TableName);
int i= 0;
foreach (DataRow dr in dt.Rows)
{
if (i < 2) { i++; continue; }
foreach (DataColumn dc in dt.Columns)
{
Response.Write(dc.ToString() + ": " + dr[dc.ToString()] + "<br />");
}
i++;
}
}
Is it possible to do with SqlServer 2012 and .NET 4? If yes, how?
Any feedback would be greatly appreciated.
Regards, artsylar