The code loops through a list of machineNames and for each machinName (There are 18 of them), it loops through a number of settings (There are 39 of them).
At present I have a generic collection to populate all the settings which is called settings.
As I am looping through the settings of each machineNames, I modify the (Fields) appropriate to that MachineName in the settings loop...
In additin I also have a class which holds the fields. This is called clsSetting
This is what I have at present:
private List<DataAccess.clsSetting> settings = new List<DataAccess.clsSetting>(); //collection to hold settings...
//generic collection to hold the result
private List<List<DataAccess.clsSetting>> results = new List<List<DataAccess.clsSetting>>();
//loop through the machineName...
foreach (DataRow dr in _dtMachineNames.Rows)
foreach (DataAccess.clsSetting s in settings)
//modify these fields for the machineName in the loop...
s.Server = strServername;
s.Result = strResult
//the other fields are not modified...
//This is where my question is:
//here I would like to have another collection which holds all the settings for each machineName
When I try the above code, i.e. results.Add(settings)
The results collection get added but NOT correctly.
It seems the data in it for each index gets over written because in the above code I modify some of the fields.
Can you please let me know what is wrong here?
Each time you loop through settings collection, you actually modify the original element in the settings collection. And again when you add settings to results, you actually add the same references again and again. Later changes on the original element (s) affect all the elements int the result list pointing to the same element.
So, you should create a copy from s before modifying and storing it to another collection if you want the elements to have independent values.
// I have used this function still problem persists
protected void killExcel(Microsoft.Office.Interop.Excel.Application exc)
List<microsoft.office.interop.excel.workbook> wbs = new List<microsoft.office.interop.excel.workbook>();
List<microsoft.office.interop.excel.worksheet> wss = new List<microsoft.office.interop.excel.worksheet>();
foreach (Microsoft.Office.Interop.Excel.Workbook wb in exc.Workbooks)
foreach (Microsoft.Office.Interop.Excel.Worksheet ws in wb.Worksheets)
wss.Add(ws); // collect worksheets
wbs.Add(wb); // collect workbooks
for (int i = 0; i < wss.Count; i++)
System.Runtime.InteropServices.Marshal.ReleaseComObject(wss[i]); // release it
wss[i] = null; // null it
for (int i = 0; i < wbs.Count; i++)
wbs[i].Close(null, null, null);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wbs[i]); // release it
wbs[i] = null; // null it
exc.Workbooks.Close(); // so you can close this
exc.Quit(); // so you can quit this
System.Runtime.InteropServices.Marshal.ReleaseComObject(exc); // release it
exc = null;
GC.Collect(); // this sets up the finalizers
GC.Collect(); //apparently this kills it
catch (Exception ex)
// deal with it fool!
I found this in the documentation on one of the COM Release functions:
// Note that COM objects that raise events within a .NET client require two Garbage Collector (GC)
// collections before they are released. This is caused by the reference cycle that occurs between
// COM objects and managed clients. If you need to explicitly release a COM object you should call
// the Collect method twice.
So I do a double GC on the main app object if I've setup any event handlers for it.
Normally not... but the problem is that all language specific char may not be read correctly. For exemple instead of ü i get | ... to solve that problem I have to decode the table (this is already done)
The problem is that some times I get tables that are already encoded correctly... in that case I don't need to decode the table...
Life is not short... the problem is only how you organize yourself
I'm trying to connect remotely from phone to pc. Currently I tested it in cradle mode. When I tried running my program (which is in the phone) it occured an error: Cannot find DbNetlib.dll. However, when I tried a pc to pc wireless connection (using an emulator) it works. It connects to the server just fine. Does anyone know how I can make my PDA phone connect to the server? I'm just copying the .exe file of my project file by the way.
i need to call a c# code in my java program. i followed the approach given in the codeproject link: http://www.codeproject.com/KB/cross-platform/javacsharp.aspx but there are some issues in generating netmodule , which is required to perform further steps. but it is giving an error
"csc /debug /t:module "bin\Debug\\HelloWorld.dll"" exited with code 9009 on using post build event command line.
E:\c#\getOLCont\getOLCont>csc /t:module form1.cs
the error is:
fatal error CS0009: Metadata file 'c:\Program Files\Reference
could not be opened -- 'File is corrupt.'
i have tried the command on different machines but there is same result.
HI, I want to iterate only those rows of excel sheet where the data have written, means if user has filled only first 15 rows then my loop should iterate to 15 only,hO wcan i do that Below is sample code which iterates up to 65536 rows,unnecessarily ,but the data are present only in first 15 or 18 rows. Please give me a solution or an idea
This is my sample code
Microsoft.Office.Interop.Excel.Application Excelobj = new Microsoft.Office.Interop.Excel.Application();
if (Excelobj == null)
MessageBox.Show("Excel couldn't be started", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);