Click here to Skip to main content
16,020,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I got an issue about Excel in c#.net. my application is simple read data from excel and put into the sql dbase. i developed with vb.net. there is no issue. but when i change to c#.net i faced an issue about object variable. my vb.net code is here:

VB
Dim obj as Object

For intInc as integer=2 to xlRange.Rows.Count
       obj = xlRange.Cells(i,1)
       Dim strValue as string = obj.value       
       SaveInDbase(strValue)
Next


but when i change to c#.net. the object don't have .value. so how should i take value from object variable.my c# code is here:
C#
Object obj=null;
for (int i=1;i<xlrange.rows.count;i++){>
        obj = xlRange.Cells[i,1];                
        String strValue = obj.value;
        SaveInDbase(strValue);
}


i also put obj.ToString(),obj as string,(string)obj. but still cannot work. i got "System.__comobject" only :(

please help me and give me suggestion , thanks in advance.
Posted

1 solution

I susoect that your issue is that VB does voodoo. Object does NOT have a value property, but if you cast it to what the object actually is an instance of, it will. Use the debugger to find out what the type of your object is, if you need to, then change the type of the object accordingly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900