Starting in 2019, the Reporting control is no longer included in Essential Studio®. If you're experiencing issues with the Syncfusion� Reporting Platform, Report Viewer, Report Designer, or Report Writer, we recommend migrating to Bold Reports, our dedicated reporting platform.

Bold Reports offers a comprehensive suite of tools and features for all your reporting needs, and we will help you make a smooth transition from the discontinued control. Our support team at https://support.boldreports.com/ is here to assist you with any questions or difficulties you may encounter during the migration process.

We thank you for choosing Syncfusion� and appreciate your understanding.

Reportviewer

Good day,
I need a simple example to implement reportviewer into asp.net web forms (visual studio 2017)
The report will have a single datasource (sql server table or view)
kind regards


7 Replies

YD Yuvaraj Devarajan Syncfusion Team November 21, 2017 06:26 AM UTC

Hi Zack, 
 
Thanks for contacting Syncfusion support.  
 
We have prepared a ReportViewer sample based on ASP.NET Web platform and it can be downloaded from below location,      
    
Please refer the below UG documentation link to create the sample in ASP.NET web platform,   
 
Also you can obtain the ASP.Net ReportViewer samples from the below build installed location,     
%userprofile%\AppData\Local\Syncfusion\EssentialStudio\version\Web\Samples\Web  
 
Regards, 
Yuvaraj D. 



ZS Zack Snyders November 21, 2017 06:45 AM UTC

Hi Yuvaraj,
Thank you for this.Can you please expand on this by providing an example where I can dynamically do a sqlserver query in C# codebehind and pass the results to the report.
Your example is fine but the data is embedded in the report itself. 
Unless I am missing something?
Thank you very much
rgs
Zack


YD Yuvaraj Devarajan Syncfusion Team November 23, 2017 06:08 PM UTC

Hi Zack, 

We can load the datasource value by passing the dataset query from command text in OnReportLoaded method in web API method as shown in below code snippet.  
  
public void OnReportLoaded(ReportViewerOptions reportOption) 
        { 
            string querystr = "SELECT Person.Address.AddressID , Person.Address.City , Person.Address.StateProvinceID FROM Person.Address"; 
            string connection = "Data Source=mvc.syncfusion.com;Initial Catalog=AdventureWorks;User Id=ssrs1;password=RDLReport1;"; 
            reportOption.ReportModel.DataSources.Clear(); 
            reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet1", Value = GetDataTable(querystr, connection) }); 
        } 
 
        public DataTable GetDataTable(string querystr, string connection) 
        { 
            string query = querystr; 
            DataTable dt = new DataTable(); 
 
            using (SqlConnection sqlConn = new SqlConnection(connection)) 
            using (SqlCommand cmd = new SqlCommand(string.Format(query), sqlConn)) 
            { 
                sqlConn.Open();                
                using (SqlDataReader reader = cmd.ExecuteReader()) 
                { 
                    dt.Load(reader); 
                    var r = dt.Rows.Count; 
                } 
                return dt; 
            } 
        } 

We have modified the shared sample and it can be downloaded from below location, 

Please refer to the below UG documentation link for more detail, 

Regards, 
Yuvaraj D. 



ZS Zack Snyders November 27, 2017 06:11 AM UTC

Hi Yuvaraj,
Thank you for this. I am almost there!
If I want to specify my database and credentials in web.config and not hardcode the connection details in OnReportLoaded and use an approach like:
            string connectionString = null;
            SqlConnection sqlCnn;
            SqlCommand sqlCmd;
            string sql = null;
            connectionString = Properties.Settings.Default.PatrolConnectionString;
            sql = "SELECT * FROM SystemUsers " + " WHERE UserName = '" + usernameTextBox.Text + "'";
            sqlCnn = new SqlConnection(connectionString);
            try
            {
                sqlCnn.Open();
                sqlCmd = new SqlCommand(sql, sqlCnn);
                SqlDataReader sqlReader = sqlCmd.ExecuteReader();
                while (sqlReader.Read())
etc.
How would I change OnReportLoaded or what would the correct approach be?
rgs
Zack


VR Vijay Raja Syncfusion Team November 28, 2017 11:30 AM UTC

  
Hi  Zack, 

We need to set the connection information in ‘OnReportLoaded’ to change the values dynamically but you can store or maintain your connection details in web.config or somewhere else based on your security needs. Please makes sure to assign the values in OnReportLoaded to update connection details dynamically. 

Regards, 
Vijay R. 



ZS Zack Snyders November 28, 2017 02:06 PM UTC

Got this working, thank you.
I included the connection string in web.config (standard method)
and in OnReportLoaded I changed it to:
      string querystr = "SELECT * FROM [dbo].[XYZ]";
      string connection = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
     
Please close 
rgs


VR Vijay Raja Syncfusion Team November 29, 2017 06:13 AM UTC

Hi  Zack, 

Thanks for your update. Please let us know if you require any further assistance on this. 

Regards, 
Vijay R. 


Loader.
Up arrow icon