I have an excel sheet that has several headers. One of the header is Param2. The variable assigned to Param2 is strParam2 in my code. This is how strParam2 is declared in my code
String strParam2 = xlRange.Cells[row, 7].Value;
My code ideally reads the cells in the excel sheets and executes a set of actions. I have given a value of 2 in a cell under Param2 in my excel sheet. In order to convert it to string, I used the line
System.Int32.TryParse(strParam2.ToString(), out iDetailLevel);
However, I am getting an error “Cannot implicitly convert double to string” I tried this line too, but however I get an error again.
System.Double.TryParse(strParam2.ToString(), out iDetailLevel);
What is the problem here? Have anybody experienced a similar thing before?
Looks like the value of that specific cell is a double and your code is trying to
implicitly convertit to a string via the=. You need to check the value of the cell and convert accordinglyString strParam2 = xlRange.Cells[row, 7].Value;Would be:
String strParam2 = xlRange.Cells[row, 7].Value.ToString();If, as you say,
strParam2is used elsewhere in code then simply create a new string to hold the header text and leave it unmodified:string headerText = xlRange.Cells[row, 7].Value.ToString();