Click here to Skip to main content
15,906,558 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, im trying to develop an application which can convert Excel worksheet to an Access db. im new for software development. Im unable to fix the below errors and would be grateful if somebody can help me to figure out the solution. thanks in advance

errors that were generated given below:

1. The best overloaded method match for Acess._Application.Quit(Access.AcQuitOption)' has some invalid arguments

2. Argument '1': cannot convert from 'Microsoft.Office.Interop.Access.AcQuitOption' to 'Access.AcQuitOption'

3. No overload for method 'FillAccessDatabase' takes '1' arguments

here is the code that i use:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        public static void CheckUpdateDBFile(string filename)
        {
            
            if (File.Exists(@"C:\Book.mdb"))
            {

                File.Delete(@"C:\Book.mdb");

            }

            Access.Application _accessData;

            _accessData = new Access.ApplicationClass();

            _accessData.Visible = false;

            _accessData.NewCurrentDatabase(@"C:\Book.mdb");

            _accessData.CloseCurrentDatabase();

            _accessData.Quit(Microsoft.Office.Interop.Access.AcQuitOption.acQuitSaveAll);

            _accessData = null;

            OleDbConnection _connection = MakeExcelConnection(filename);

            FillAccessDatabase(_connection);

        }

        private static OleDbConnection MakeExcelConnection(string fileName)
        {

            string _filename = @"C:\NMS_List_Export.xls";

            string _conn;

            _conn = "Provider=Microsoft.Jet.OLEDB.12.0;" + @"Data Source=" + _fileName + ";" +

            "Extended Properties=Excel 12.0;";
            OleDbConnection _connection = new OleDbConnection(_conn);

            return _connection;
        }

        public static void FillAccessDatabase()
        {
            OleDbCommand _command = new OleDbCommand();

            _command.Connection = _connection;

            try
            {

                _command.CommandText = @"SELECT * INTO [MS Access;Database=C:\Book.mdb].[NMS_List_Export] FROM [NMS_List_Export$]";

                _connection.Open();

                _command.ExecuteNonQuery();

                _connection.Close();

                MessageBox.Show("The import is complete!");

            }

            catch (Exception)
            {

                MessageBox.Show("Import Failed, correct Column name in the sheet!");
            }
        }

    }
}
Posted
Updated 12-Dec-11 3:34am
v2

1 solution

I've found some issues in your code also:
- In function MakeExcelConnection, you have a variable named "_fileName" in which your argument is "fileName" and the private variable inside that function is "_filename".

Solution to the errors you encountered:
#1 and #2 try to change the Platform target to x86

#3. You should modify your
public static void FillAccessDatabase()
to
public static void FillAccessDatabase(OleDbConnection _connection)
 
Share this answer
 
Comments
hansikaat 13-Dec-11 5:35am    
Hi Seravan, thanks. i followed your directions and i was able to get rid of errors except the 1st and 2nd. i changed the platform to x86 but still i find those errors on the application.

this is how i changed the platform:

Configuration Manager-->Active Solution Platform--> New --> Type the new platform x86

please help
seravan 13-Dec-11 19:27pm    
Hi Hansiak, thanks for the reply. I see so it doesn't solve 1st and 2nd. I would like to ask the following:
1. Have you added Microsoft.Office.Interop.Access in the references? If yes, what version?
2. Have you tried putting using Microsoft.Office.Interop;?

In my local it did work. Here's what I did:
1. Added Microsoft.Office.Interop.Access as references version 11.0.0.0
2. Added using Microsoft.Office.Interop; in my code
3. Change my Platform target to x86 since i'm using a 64bit OS. I change this thru double clicking the Properties > Click Build > change the Platform target to x86

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