将列表传递给函数C#3.5 [英] Pass List to a function C# 3.5

查看:112
本文介绍了将列表传递给函数C#3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我有一个在VS 2005中运行良好的网站,我刚刚将其升级到VS 2010,该网站中有很多报告,对于每个报告,我都将公司详细信息作为参数传递给这些细节,这些详细信息都在类库项目中获取.代码会像这样

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()));
.......



我从这样的report1.aspx.cs页面调用此



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

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);
.....







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



我在Google中进行了搜索,但没有找到解决方法

请帮助我解决此问题.



i searched in the google but didnt get a solution

Please help me to solve this

推荐答案

您必须调试Web应用程序.我可以在GetCompanyInfo方法的开头看到一条try语句,并且导致没有任何内容添加到作为参数传递给列表的原因很可能是该方法中发生了异常.

因此,它要么是为您调试,要么是使用日志记录语句对代码进行大量修饰(请参阅 Log4N [
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


我认为:

I think this:

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



应该是:



should be:

DataRow row = dtCompanyInfo.Rows[0];
paramList.Add(new ReportParameter("Company_Name",row["CompanyName"].ToString()));


尊敬的朋友,

最后,我得到了解决方案.
包含函数GetCompanyInfo(string ConnectionString,List< ReportParameter> paramList)的类库正在使用ReportViewer 8.0.0.0作为引用,但是包含ReportViewer的aspx页面引用了10.0.0.0.添加ReportParameter时会导致错误,这意味着BoatParameter组件中存在ReportParameter,从而产生冲突.因此,我从类库中删除了现有引用,并添加了新版本.
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.


这篇关于将列表传递给函数C#3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆