如何通过Web应用程序中的存储过程在报表查看器中进行报表 [英] How to make report in report viewer through stored procedure in web application

查看:61
本文介绍了如何通过Web应用程序中的存储过程在报表查看器中进行报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



i希望通过报表查看器控件进行报表,并且我创建了名为'usp_FetchAllEmp'的存储过程。它具有where条件。(如Id = @ id)但我不明白如何绑定报表数据源,最后如何在报表查看器控件中显示所有数据。



任何人都可以提供给我的代码片段,以便我可以尝试并解决我的问题。



plz帮助我..



i want to make a report through report viewer control and i have made stored procedure with the name 'usp_FetchAllEmp". it has where condition.(like Id=@id) but i am not getting understand that how to bind with report data source and finally how to show all the data in report viewer control.

can anyone provide me code snippet for that so that i could tried that and resolve my issue.

plz help me..

推荐答案

string selection;
        string sqlQry;
      ReportDataSource sReportDataSource = new ReportDataSource();
        MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["LocalMySqlServer"].ConnectionString);
public void viewreports()
       {

           this.ReportViewer1.Reset();
          


           sReportDataSource.Name = "dsscpreport_dtscpreport";
           sReportDataSource.Value = objImportBal.GetReportData(sqlQry, con);
           ReportViewer1.LocalReport.DataSources.Clear();
           ReportViewer1.LocalReport.DataSources.Add(sReportDataSource);
         
           ReportViewer1.LocalReport.ReportPath = "Reports/Sales_Reports/Sales_Transaction/rdlcsalesregister.rdlc";
         
          

         
           ReportViewer1.LocalReport.Refresh();

       }
 public DataTable GetReportData(string Query,MySqlConnection con)
        {

            MySqlDataAdapter adp = new MySqlDataAdapter(Query, con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            return ds.Tables[0];
            
        }





此处取代查询U必须调用存储过程并填充数据表



here Instead Of Query U Have To Call Stored Procedure And Fill The Datatable


ReportDocument rptDoc = null;

string [] strDSUP;

string [] strServerName;

string [] strDatabaseName ;

string [] strPassword;

string [] strUserID;

clsFireProp objBO = null;

系统。 IO.MemoryStream objStr = null;

尝试

{

objBO = new clsFireProp();

string strPath =../Reports/rptFireInsurance.rpt;

rptDoc = new ReportDocument();

rptDoc.Load(Server.MapPath(strPath));

CrystalDecisions.Shared.TableLogOnInfo myLogin;

string strConnectionString = BO.clsFileManager.getDecrpt值(sqlConnection,ConnString);

strDSUP = strConnectionString.Split(';');



/ *

在岸上取消注释这些行

strServerName = strDSUP [0] .Split('=');

strDatabaseName = strDSUP [1] .Split( '=');

strPassword = strDSUP [3] .Split('=');

strUserID = strDSUP [2] .Split('=');

* /





//在岸上评论以下几行:接下来4行

strServerName = strDSUP [0] .Split('=');

strDatabaseName = strDSUP [1] .Split('=');

strPassword = strDSUP [4] .Split('=');

strUserID = strDSUP [3] .Split('=');





foreach(rptDoc.Database.Tables中的CrystalDecisions.CrystalReports.Engine.Table mytable)

{

myLogin = mytable.LogOnInfo;

myLogin.ConnectionInfo.ServerName = strServerName [1];

myLogin.ConnectionInfo.DatabaseName = strDatabaseName [1];

myLogin.ConnectionInfo.Password = strPassword [1];

myLogin.ConnectionInfo.UserID = strUserID [1];

mytable.ApplyLogOnInfo(myLogin);

}

int subRepCount = rptDoc.Subreports.Count;

int subRepStart;

if(subRepCount> 0)

{

for(subRepStart = 0; subRepStart< =(subRepCount - 1); subRepStart ++)

{

foreach(CrystalDecisions.CrystalReports.Engine.Table myTable_loopVariable in rptDoc.Subreports [subRepStart] .Database.Tables)

{

CrystalDecisions.CrystalReports.Engine.Table mytable;

mytable = myTable_loopVariable;

myLogin = mytable.LogOnInfo;

myLogin.ConnectionInfo.ServerName = strServerName [1];

myLogin.ConnectionInfo.DatabaseName = strDatabaseName [1];

myLogin.ConnectionInfo.Password = strPassword [1];

myLogin.ConnectionInfo.UserID = strUserID [1];

mytable.ApplyLogOnInfo(myLogin);

}

}

}

objBO.QuoteNo = QuoteID;

rptDoc.SetParameterValue(@ QuotationNo,objBO.QuoteNo);

//crViewer.ReportSource = rptDoc;

//crViewer.DataBind( );;

/ *由Avinash编写的代码* /

objStr =(System.IO.MemoryStream)rptDoc.ExportToStream(ExportFormatType.PortableDocFormat); ;

Response.Clear();

Response.Buffer = true;

Response.ContentType =application / pdf;

Response.BinaryWrite(objStr.ToArray());

rptDoc.Refresh();

Response.End();
ReportDocument rptDoc = null;
string[] strDSUP;
string[] strServerName;
string[] strDatabaseName;
string[] strPassword;
string[] strUserID;
clsFireProp objBO = null;
System.IO.MemoryStream objStr = null;
try
{
objBO = new clsFireProp();
string strPath = "../Reports/rptFireInsurance.rpt";
rptDoc = new ReportDocument();
rptDoc.Load(Server.MapPath(strPath));
CrystalDecisions.Shared.TableLogOnInfo myLogin;
string strConnectionString = BO.clsFileManager.getDecrptValue("sqlConnection", "ConnString");
strDSUP = strConnectionString.Split(';');

/*
Uncomment these lines in onshore
strServerName = strDSUP[0].Split('=');
strDatabaseName = strDSUP[1].Split('=');
strPassword = strDSUP[3].Split('=');
strUserID = strDSUP[2].Split('=');
*/


//Comment the following lines in onshore :Next 4 lines
strServerName = strDSUP[0].Split('=');
strDatabaseName = strDSUP[1].Split('=');
strPassword = strDSUP[4].Split('=');
strUserID = strDSUP[3].Split('=');


foreach (CrystalDecisions.CrystalReports.Engine.Table mytable in rptDoc.Database.Tables)
{
myLogin = mytable.LogOnInfo;
myLogin.ConnectionInfo.ServerName = strServerName[1];
myLogin.ConnectionInfo.DatabaseName = strDatabaseName[1];
myLogin.ConnectionInfo.Password = strPassword[1];
myLogin.ConnectionInfo.UserID = strUserID[1];
mytable.ApplyLogOnInfo(myLogin);
}
int subRepCount = rptDoc.Subreports.Count;
int subRepStart;
if (subRepCount > 0)
{
for (subRepStart = 0; subRepStart <= (subRepCount - 1); subRepStart++)
{
foreach (CrystalDecisions.CrystalReports.Engine.Table myTable_loopVariable in rptDoc.Subreports[subRepStart].Database.Tables)
{
CrystalDecisions.CrystalReports.Engine.Table mytable;
mytable = myTable_loopVariable;
myLogin = mytable.LogOnInfo;
myLogin.ConnectionInfo.ServerName = strServerName[1];
myLogin.ConnectionInfo.DatabaseName = strDatabaseName[1];
myLogin.ConnectionInfo.Password = strPassword[1];
myLogin.ConnectionInfo.UserID = strUserID[1];
mytable.ApplyLogOnInfo(myLogin);
}
}
}
objBO.QuoteNo = QuoteID;
rptDoc.SetParameterValue("@QuotationNo", objBO.QuoteNo);
//crViewer.ReportSource = rptDoc;
//crViewer.DataBind();
/*Codes written by Avinash*/
objStr = (System.IO.MemoryStream)rptDoc.ExportToStream(ExportFormatType.PortableDocFormat); ;
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(objStr.ToArray());
rptDoc.Refresh();
Response.End();


这篇关于如何通过Web应用程序中的存储过程在报表查看器中进行报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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