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 appreciatedThis post has been edited by Redian: 1 Jul, 2008 - 03:02 PM