Click here to Skip to main content
16,017,351 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear Friends,

I have a website which is running perfectly in VS 2005.I just upgrade this into VS 2010.I have many reports in the site.For each report I am passing the company detail as parameter.These details are fetching in a class library project.The code will be like this

public void GetCompanyInfo(string ConnectionString,List<ReportParameter> paramList)
{
try
{
DataTable dtCompanyInfo = obj.GetCompanyInfo();                
paramList.Add(new ReportParameter("Company_Name",dtCompanyInfo.Rows[0]"CompanyName"].ToString()));
.......


I am calling this from report1.aspx.cs page like this

XML
List<ReportParameter> paramList = new List<ReportParameter>();
            paramList.Add(new ReportParameter("RFE_ID",ddlRFENo.SelectedValue));
            paramList.Add(new ReportParameter("Language",Session["lang"].ToString()));
            objUIFunctions.GetCompanyInfo(Session["ConnectionString"].ToString(),paramList);
.....



SQL
after the add statement executed the exception is like this
"Attempted to access an element as a type incompatible with the array."


i searched in the google but didnt get a solution

Please help me to solve this
Posted
Updated 20-Apr-11 2:17am
v4
Comments
BobJanova 20-Apr-11 9:48am    
Exceptions will give you a stack trace. Look at the stack trace, it will tell you where your mistake is.

You have to debug your web application. I can see a try statement right at the start of your GetCompanyInfo method and the cause that nothing gets added to the list you passed in as a parameter is most likely that there is an exception occuring in the method.

So it's either debugging for you or heavily spicing your code with logging statements (See Log4N[^]).

Best Regards,

-MRB
 
Share this answer
 
v2
Comments
AshiqueAhammed 20-Apr-11 8:10am    
My Friend,
after the add statement executed the exception is like this
"Attempted to access an element as a type incompatible with the array."
thanks for your reply.
Manfred Rudolf Bihy 20-Apr-11 8:21am    
Doesn't have anything to do with parameList but rather with the second parameter passed to the constructor of ReportParameter:

dtCompanyInfo.Rows[0]["CompanyName"].ToString()

Split this operation into several parts and you'll get the drift what's going wrong.
You could have found out that by yourself as this is the only code in your program that has anything to do with arrays.
AshiqueAhammed 21-Apr-11 1:08am    
Dear,
I tried it like this
DataRow dr = dtCompanyInfo.Rows[0];
string cmpName = dr["CompanyName"].ToString();
paramList.Add(new ReportParameter("Company_Name", cmpName));

But still i am getting the same error.
I just went through the exception details and i saw the error like this

StackTrace: at System.Collections.Generic.List`1.Add(T item)

i also noticed something like this
{mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
is this version any problem

Please help me to solve this
Manfred Rudolf Bihy 21-Apr-11 16:42pm    
You said in your question that the method GetCompanyInfo was in a separate class library which is then being referenced from your web project. If the class library is using one definition of ReportParameter and your web project has another definition of ReportParameter that could explain the error your getting.
Please make sure that there is only one definition of type ReportParameter and one and the same is being used in both projects.

Please check that.
Manfred Rudolf Bihy 21-Apr-11 16:43pm    
Could it be that your class library project is .NET 2.0 and not .NET 3.5 as you question implies?
I think this:

C#
paramList.Add(new ReportParameter("Company_Name",dtCompanyInfo.Rows[0]"CompanyName"].ToString()));


should be:

C#
DataRow row = dtCompanyInfo.Rows[0];
paramList.Add(new ReportParameter("Company_Name",row["CompanyName"].ToString()));
 
Share this answer
 
Comments
BobJanova 20-Apr-11 9:47am    
Apart from the missing bracket in the OP's code (which I guess is just a copy/paste typo), these are equivalent.
AshiqueAhammed 21-Apr-11 1:07am    
Dear,
I tried it like this
DataRow dr = dtCompanyInfo.Rows[0];
string cmpName = dr["CompanyName"].ToString();
paramList.Add(new ReportParameter("Company_Name", cmpName));

But still i am getting the same error.
I just went through the exception details and i saw the error like this

StackTrace: at System.Collections.Generic.List`1.Add(T item)

i also noticed something like this
{mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
is this version any problem

Please help me to solve this
Dear Friends,

Finaly i got the solution.
The class library containing the function GetCompanyInfo(string ConnectionString,List<ReportParameter> paramList) was using ReportViewer 8.0.0.0 as Reference, But the aspx page containing ReportViewer is referencing 10.0.0.0. It makes the error when adding the ReportParameter means ReportParameter exist in boath assembly that makes the conflict. So i removed the existing reference from class library and added the new version.
 
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