Click here to Skip to main content
15,944,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am export data into dbf format in asp.net. It's workine fine in 32 bit machine. But it's not working in 64 bit machine Why?

Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine Error in 64 bit machine. While I have installed this AccessDatabaseEngine_x64 in 64 bit machine.


My Code-

public ActionResult ExportToDBF(string itemfilter, string historyid)
{
try
{
var selectManageDataPriceList = new List<invoicemodel>();
InvoiceModel model = new InvoiceModel();

model.InvoiceHistoryId = Convert.ToInt32(historyid);
List<getallvendorinvoicepricetempcomparedata_result> dataPriceList;

model.Checked = true;
dataPriceList = InvoicePriceBL.GetAllVendorInvoicePriceTempCompareData(Convert.ToInt32(historyid)).ToList();

OleDbConnection dBaseConnection = null;
string filepath = null;

filepath = Server.MapPath("~/Content/CSVFile/");
string TableName = "T" + DateTime.Now.ToLongTimeString().Replace(":", "").Replace("AM", "").Replace("PM", "");

using (dBaseConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " + " Data Source=" + filepath + "; " + "Extended Properties=dBase IV"))
{
dBaseConnection.Open();

OleDbCommand olecommand = dBaseConnection.CreateCommand();

if ((System.IO.File.Exists(filepath + "" + TableName + ".dbf")))
{
System.IO.File.Delete(filepath + "" + TableName + ".dbf");
olecommand.CommandText = "CREATE TABLE [" + TableName + "] (VendorItemId varchar(10), InvoiceHistoryId varchar(10), Price varchar(10), TempPrice varchar(10), DistributorItemNumber varchar(100), ItemName varchar(100))";
olecommand.ExecuteNonQuery();
}
else
{
olecommand.CommandText = "CREATE TABLE [" + TableName + "] (VendorItemId varchar(10), InvoiceHistoryId varchar(10), Price varchar(10), TempPrice varchar(10), DistributorItemNumber varchar(100), ItemName varchar(100))";
olecommand.ExecuteNonQuery();
}

OleDbDataAdapter oleadapter = new OleDbDataAdapter(olecommand);
OleDbCommand oleinsertCommand = dBaseConnection.CreateCommand();

foreach (DataRow dr in GenerateData(model.InvoiceHistoryId).Rows)
{
string Price = dr["Price"].ToString();
string TempPrice = dr["TempPrice"].ToString();

oleinsertCommand.CommandText = "INSERT INTO [" + TableName + "] ([Price],[TempPrice]) VALUES ('" + Price + "','" + TempPrice + "')";
oleinsertCommand.ExecuteNonQuery();
}
}

FileStream sourceFile = new FileStream(filepath + "" + TableName + ".dbf", FileMode.Open);
float FileSize = 0;
FileSize = sourceFile.Length;
byte[] getContent = new byte[Convert.ToInt32(Math.Truncate(FileSize))];
sourceFile.Read(getContent, 0, Convert.ToInt32(sourceFile.Length));
sourceFile.Close();
Response.ClearContent();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/dbf";
Response.AddHeader("Content-Length", getContent.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=InvoicePriceExport.dbf;");
Response.BinaryWrite(getContent);
Response.Flush();
System.IO.File.Delete(filepath + "" + TableName + ".dbf");
Response.End();

return File("application/dbf", "InvoicePriceExport.dbf");

}
catch (Exception ex)
{
throw ex;
}
}

private DataTable GenerateData(int historyid)
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("Price", typeof(string)));
dt.Columns.Add(new DataColumn("TempPrice", typeof(string)));
int totalRow = 25;

var selectManageDataPriceList = new List<invoicemodel>();
InvoiceModel model = new InvoiceModel();

model.InvoiceHistoryId = Convert.ToInt32(historyid);
List<getallvendorinvoicepricetempcomparedata_result> dataPriceList;

model.Checked = true;
dataPriceList = InvoicePriceBL.GetAllVendorInvoicePriceTempCompareData(Convert.ToInt32(historyid)).ToList();
if (dataPriceList.Count() > 0)
{
foreach (var item in dataPriceList)
{
dr = dt.NewRow();
dr["Price"] = item.CurrentPrice;
dr["TempPrice"] = item.Price;
dt.Rows.Add(dr);
}
}
return dt;
}
Posted
Updated 2-Feb-16 1:40am
v2
Comments
NightWizzard 2-Feb-16 13:37pm    
Think you'll need a dBase library to do that - but I'm afraid you won't find any that can be used with today's technologies. It's too old and no longer supported.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900