Hello I have the code below that for some reason is not working:
I use oledb to fill a dataset from a pipe delimited file that is uploaded through a fileupload control on an asp.net web application. I then take the data table and then use sql bulk copy to copy the data to a table i have setup in sql.
protected void btnUpload_Click(object sender, EventArgs e)
{
string filepath = fileUpload1.PostedFile.FileName;
PerformBulkCopy(GencoUpload(filepath));
}
public static DataTable GencoUpload(string path)
{
string full = Path.GetFullPath(path);
string file = Path.GetFileName(full);
string dir = Path.GetDirectoryName(full);
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=\"" + dir +
"\\\";" + "Extended Properties=\"text;HDR=Yes;Format=Delimited(|)\";";
string query = "SELECT * FROM " + file;
DataTable dt = new DataTable();
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
try
{
dAdapter.Fill(dt);
}
catch
{
// catch code
}
dAdapter.Dispose();
return dt;
}
private void PerformBulkCopy(DataTable GencoInfo)
{
string conStr = ConfigurationManager.ConnectionStrings["EDI"].ConnectionString;
using (SqlBulkCopy bulkcopy = new SqlBulkCopy(conStr))
{
bulkcopy.DestinationTableName = "dbo.GencoUploadTempTable";
bulkcopy.WriteToServer(GencoInfo);
}
}
Can someone help me with why this isnt loading into my sql database? Thank you.
This should do the work……………