mohit gupta

mohit gupta

  • NA
  • 145
  • 59.5k

Unrecognized database format in asp.net,C#

Oct 5 2013 3:36 AM
hi all..I m converting sql database in dbf(foxpro).but here create a error..plse help me?

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:

Line 31: 
Line 32:             OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + directory + DBF_FileName + ";");            //oCmd.CommandText = "SELECT * FROM " + FilePath + DBF_FileName;
Line 33:             connection.Open();
Line 34:             OleDbCommand command = connection.CreateCommand();
Line 35: 
my code is...
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;
            }


        }
        }
    }
   

Answers (2)