Unrecognized database format 'E:\TEST.dbf'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Data.OleDb.OleDbException: Unrecognized database format 'E:\TEST.dbf'.
Source Error:
|
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Data.Odbc;
using System.Data.OleDb;
namespace EDS
{
public partial class foxpro : System.Web.UI.Page
{
String strcon = ConfigurationManager.ConnectionStrings["con"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select * from SaveData", strcon);
DataSet ds = new DataSet();
da.Fill(ds, "SaveData");
string directory = "E://";
string DBF_FileName = "TEST.dbf";
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + directory + DBF_FileName + ";"); //oCmd.CommandText = "SELECT * FROM " + FilePath + DBF_FileName;
connection.Open();
OleDbCommand command = connection.CreateCommand();
if (System.IO.File.Exists(directory + @"TEST.DBF"))
{
command.CommandText = "delete FROM SaveData";
}
else
{
command.CommandText = "CREATE TABLE Test (ID int, FileName varchar(50),FilePath varchar(50))";
command.ExecuteNonQuery();
command.CommandText = "SELECT * FROM SaveData";
OleDbDataAdapter adapter = new OleDbDataAdapter(command);
OleDbCommand insertCommand = connection.CreateCommand();
insertCommand.CommandText = "INSERT INTO Test (ID, FileName,FilePath) VALUES (pID,pname,plast_name)";
}
foreach (DataRow dr in ds.Tables["SaveData"].Rows)
{
OleDbCommand insertCommand = connection.CreateCommand();
int id = int.Parse(dr["ID"].ToString());
string name = dr["filename"].ToString();
string last_name = dr["filepath"].ToString();
insertCommand. Parameters.Add("pID", OleDbType.Integer, 4, ID);
insertCommand.Parameters.Add("pname", OleDbType.VarChar, 50, name);
insertCommand.Parameters.Add("plast_name", OleDbType.VarChar, 50, last_name);
insertCommand.UpdatedRowSource = UpdateRowSource.None;
}
}
}
}
mohit guptaPosted Oct 6, 2013, 11:58 PM
venkata kumarPosted Oct 5, 2013, 6:18 AM
try the fallowing code
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=Excel 12.0;"; //Create Connection to Excel work book
OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);
excelConnection.Open();
OleDbDataAdapter da = new OleDbDataAdapter("Select [ISBN/Code],[Title],[Publisher],[Author],[Qty],[Price],[Rate In INR],[Disc%],[Value In INR] from [Sheet1$]", excelConnection);