Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am getting index out of range exception....in below line..
C#
rng.set_Item(16, 1, odr60["phase_name"].ToString().Replace("\r", "").Replace("\\n", "\n").Replace("\\r", ""));

below is the code...Please help me to resolve this issue
C#
  strNonWeighedTotalTab = Session["TotalNonWeightedExcel"].ToString();
            ocmd = new OracleCommand();
            ocmd.Connection = DBConn;
            ocmd.CommandText = strNonWeighedTotalTab;
            OracleDataReader odr60 = ocmd.ExecuteReader();
            int cntt2 = 0;
            while (odr60.Read())
            {
                cntt2 = cntt2 + 1;
                rng.set_Item(16, 1, odr60["phase_name"].ToString().Replace("\r", "").Replace("\\n", "\n").Replace("\\r", ""));
                rng.set_Item(16, 2, odr60["req_analysis_high"].ToString().Replace("\r", "").Replace("\\n", "\n").Replace("\\r", ""));
                rng.set_Item(16, 3, odr60["req_analysis_medium"].ToString().Replace("\r", "").Replace("\\n", "\n").Replace("\\r", ""));
}
Posted
Updated 7-Aug-13 20:11pm
v2
Comments
Bernhard Hiller 8-Aug-13 2:14am    
What's "rng"? How does that set_Item function look like?
16Sonali 8-Aug-13 4:16am    
Excel.Range rng = null;
jaideepsinh 8-Aug-13 2:41am    
Hello sonali,
Did you use any loop? Because this type of error comes when data are more then you expectation.
16Sonali 8-Aug-13 4:18am    
yes in bindgrid function
Asp_Learner 8-Aug-13 10:38am    
Please post your full code ,if possible.

1 solution

"Excel.Range rng = null;" Then I'd actually expect a NullRefereceException. Well, look at the place where you set the range to some value. And then use a "bigger" range allowing for a sufficient amount of rows and columns.
 
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