Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

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..
Posted

C#
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];
            
        }


here Instead Of Query U Have To Call Stored Procedure And Fill The Datatable
 
Share this answer
 
v2
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();
 
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