So I have the following code to take a Excel file and write it to a table in my DB.
string target = Server.MapPath("~/Upload");
if (fupStation.HasFile)
{
fupStation.SaveAs(System.IO.Path.Combine(target, fupStation.FileName));
string connectionString = String.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=YES;IMEX=1;""", target + "\\" + fupStation.FileName); string query = String.Format("select * from [{0}$]", "Client Station Assignments");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dsStation = new DataSet();
dataAdapter.Fill(dsStation);
DataTable dtStation = new DataTable();
dtStation = dsStation.Tables[0];
gvOne.DataSource = dtStation;
gvOne.DataBind();
using (SqlBulkCopy s = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["cnSQL"].ConnectionString))
{
s.DestinationTableName = "StationImport";
s.NotifyAfter = 100;
s.WriteToServer(dtStation);
s.Close();
}
}
So Here is the issue. It reads the file and populate the Datatable just fine (proven by populating the Grid with it) And I know the SQLBulkCopy code is being called, but in the end it gives no errors, but nothing shows up in my table!
Anyone been thru this before? This is my first time using BulkCopy (and reading files too!) so I wouldn't be suprized if I am doing soemthing wrong.
Thanks