Hello All,
I'm a newbie on C# and i have worked exclusively on Access Databases and ADO.NET - OLEDB. This time I have a simple Excel 2010 Sheet made by 5 columns. I have to iterate thru the first 3, checking inside and then write data on 4th and 5th.
This file Excel is a "compatibility mode" and shared in a little office network and used by about 20 people max.
I have this problem:
If I write data into the 4 and 5th cells on my local Pc or where I have the IDE (Visual Studio 2008) all is working normally, I can write data without any problem; but, installing the program on my Desktop at work and working on LAN, happens the following:
I write data, I save data, I close the program, then I open the sheet and I see my data written; but after a while (just a few minutes), they are disappeared.
The debug in VS2008 doesn't report errors.
So I'm thinking the problem could be given by the following string, but I don't know if there is a real error in it.
----------------------------------------------------------------------------------------------------
public static string connSQL_ExtFileChecked()
{
string connessioneSQL;
string extFile=Path.GetExtension(VarP.fileAnalizzato);
if (extFile == ".xls")
{
connessioneSQL = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + VarP.fileAnalizzato
+ ";" + "Mode=ReadWrite;" + "Extended Properties=Excel 8.0;";
}
else
{
connessioneSQL = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + VarP.fileAnalizzato
+ ";" + "Mode=ReadWrite;" + "Extended Properties=Excel 12.0;";
}
return connessioneSQL;
}
Could anyone help me, please ?
Regards,
Pim.
Loading
Mayur DighePosted Jan 16, 2012, 12:28 PM
i.e. for Excel 8.0 : - file extension is '.xls'
and for Excel 12.0 : - file extension is '.xlsx'
just don't directly assign connection string without verifying the Extension of file is both statement i.e. in if(...) and else if(...)
Else you can throw the Exception if file is NOT of proper Extension, since the user of this Application you are Developing might select a File with Wrong extension .. i.e. file with extensions like .doc, .docx, .txt, .rtf etc..