I'm not sure what to give, Here's the sections that I would think are important:
CODE
public void SaveToExcel()
{
bool InterestedCustomersExists = false;
if (Clients != null)
{
try
{
conn.Open();
if (File.Exists(ConferenceName + ComputerNumber + ".xls"))
{
do
{
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
String[] excelSheets = new String[dt.Rows.Count];
int i = 0;
foreach (DataRow row in dt.Rows)
{
string strSheetTableName = row["TABLE_NAME"].ToString();
excelSheets[i] = strSheetTableName.Substring(0, strSheetTableName.Length - 1);
i++;
}
i = 0;
foreach (string tablename in excelSheets)
{
if (tablename == "IntCust") InterestedCustomersExists = true;
}
if (InterestedCustomersExists == false)
{
string Command = @"CREATE TABLE [InterestedCustomers] ([First Name] text, [Last Name] text, [Address Line 1] text, [Address Line 2] text, [City] text, [State] text, [Zip Code] text, [Home Phone Number] text, [Business Phone Number] text, [Position] text, [Email Address] text, [Subjects Taught] text, [Projector Use (X times per week)] text, [School Name] text, [School Address Line 1] text, [School Address Line 2] text, [School City] text, [School State] text, [School Zip] text, [School Phone Number] text, [Software Type Requested] text, [License for Subject] text, [Wand Trial?] text, [Comments] text)";
cmdCreateTable = new OleDbCommand(Command, conn);
cmdCreateTable.ExecuteNonQuery();
}
} while (InterestedCustomersExists == false);
}
for (int i = 0; i <= Clients.Count - 1; i++)
{
this.cmdCustomers.Parameters.Clear(); //Clears the parameters from the last time around
foreach (OleDbParameter Par in Clients[i].ParametersforWriting)
{
this.cmdCustomers.Parameters.Add(Par);
}
{
this.cmdCustomers.ExecuteNonQuery(); //Execute the command
}
}
Clients = null;
}
finally
{
conn.Close();//Close the connection
}
}
}
//and the original command object is created here:
public Form2(string ConferenceName, int ComputerNumber, object SessLogin, string FilePath)
{
InitializeComponent();
//prevent form redraw from flashing
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
//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=" + FilePath + "\\" + ConferenceName + ComputerNumber + ".xls; Extended Properties=\"Excel 8.0;HDR=YES;Readonly=FALSE\"";
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] , [School Phone Number] , [Software Type Requested] , [License for Subject] , [Wand Trial?] , [Comments] )
VALUES (@FirstName, @LastName, @Address1, @Address2, @City, @State, @Zip, @HomePhone, @BusinessPhone, @Position, @Email, @Subjects, @Projector, @School, @SchoolAddress1, @SchoolAddress2, @SchoolCity, @SchoolState, @SchoolZip, @SchoolPhone, @Software, @SubjectLicense, @WandTrial, @Comments)";
cmdCustomers = new OleDbCommand(Command, conn);
}
I don't think there's anything wrong with my connection or commands, I really feel like its some preference I need to change or something...