Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 107,706 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,062 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



ADO.NET Database for excel writing returning an error

 
Reply to this topicStart new topic

ADO.NET Database for excel writing returning an error, The Microsoft Jet database engine could not find the object 'Inter

Redian
post 1 Jul, 2008 - 01:52 PM
Post #1


New D.I.C Head

*
Joined: 28 Dec, 2007
Posts: 21

So I'm trying to output data to an excel file using ADO.NET operations. The problem I think I'm having is that the spreadsheet I'm trying to access doesn't exist. Basically the application collects information from interested customers. Saves it to an item of a class that contains specifications for all of it in the List<Clients>, sets these parameters to the OleDbCommand, and then executes it. The error, The Microsoft Jet database engine could not find the object 'InterestedCustomers$'., occurs on the ExecuteNonQuery line. "The Microsoft Jet database engine could not find the object 'InterestedCustomers$'. Make sure the object exists and that you spell its name and the path name correctly."

Here are what I believe to be the important excerpts. Any enlightenment would be very much appreciated. And yes, I'm aware this code is probably not the most efficient, points would be appreciated.
CODE

        private List<Person> Clients = new List<Person>();
        public string ConferenceName;
        public int ComputerNumber;
        public object SessLogin;
        public Close Logoff;
        private DataSet dsCustomers = new DataSet();
        string ConnectionString;
        private OleDbConnection conn;
        private OleDbCommand cmdCustomers;

public Form2(string ConferenceName, int ComputerNumber, object SessLogin)
        {
            InitializeComponent();
            //collect the information passed from the first form
            this.ConferenceName = ConferenceName;
            this.ComputerNumber = ComputerNumber;
            this.SessLogin = SessLogin;
            //Set up the OleDb connection and commands for inserting rows, using the passed information.
            ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + ConferenceName + ComputerNumber + ".xls;Extended Properties=\"Excel 8.0;HDR=YES;\"";
            conn = new OleDbConnection(ConnectionString);
            string Command = @"INSERT INTO [InterestedCustomers$] (""First Name"", ""Last Name"", ""Address Line 1"", ""Address Line 2"", ""City"", ""State"", ""Zip Code"", ""Home Phone Number"", ""Business Phone Number"", ""Position"", ""Email Address"", ""Subjects taught"", ""Projector use X times per week"", ""School Name"", ""School Address Line 1"", ""School Address Line 2"", ""School City"", ""School State"", ""School Zip Code"", ""School Phone Number"", ""Type of Software"", ""License for Subject"", ""Wand Trial?"", ""Comments"") VALUES (@FirstName, @LastName, @Address1, @Address2, @City, @State, @Zip, @HomePhone, @BusinessPhones, @Position, @Email, @Subjects, @Projector, @School, @SchoolAddress1, @SchoolAddress2, @SchoolCity, @SchoolState, @SchoolZip, @SchoolPhone, @Software, @SubjectLicense, @WandTrial, @Comments)";
            cmdCustomers = new OleDbCommand(Command, conn);
        }
public void SaveToExcel()
        {
            for (int i = 0; i <= Clients.Count - 1; i++)
            {
                cmdCustomers.Parameters.Clear(); //Clears the parameters from the last time around
                foreach (OleDbParameter Par in Clients[i].ParametersforWriting)
                {
                    cmdCustomers.Parameters.Add(Par);
                }
                {
                    conn.Open(); //Open the connection
                    cmdCustomers.ExecuteNonQuery(); //Execute the command
                    conn.Close();//Close the connection
                }
            }

Thanks!

EDIT: Looking into it, I've discovered the problem isn't in creating the Database, its in finding the table. Any help in addressing this would be appreciated

This post has been edited by Redian: 1 Jul, 2008 - 03:02 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 8/30/08 02:09AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month