This is a migrated thread and some comments may be shown as answers.

How to apply sqlDataSource on Winforms report viewer ?

1 Answer 357 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
박문석
Top achievements
Rank 1
박문석 asked on 05 Mar 2020, 02:34 AM

Hi,

I want to make a report by using report viewer on Winforms(C#). 

Report was designed on Visual studio 2019. 

When I add and set a sqlDataSource on Report Designer.  it is shown correctly.

 

I create a report on report viewer on Winforms(C#) by dynamic data with SQL query.

How can I set sqlDataSource ?

 

Here is my code.

 

private void reportViewer1_Load(object sender, EventArgs e)
        {
            TypeReportSource typeReportSouce = new TypeReportSource();
            typeReportSouce.TypeName = "SalesManager.Products.BarcodePrintReport, SalesManager, Version=0.9.24.1, Culture=neutral, PublicKeyToken=null";
            typeReportSouce.Parameters.Add(new Telerik.Reporting.Parameter("Barcode", "O43659"));

            SqlDataSource sqlDataSource = new SqlDataSource();
            sqlDataSource.ProviderName = "MySql.Data.MySqlClient";
            sqlDataSource.ConnectionString = "Server=********;Port=****;Database=****;Uid=****;Pwd=*****;CharSet=utf8;Convert Zero Datetime=True";
            sqlDataSource.SelectCommand = "SELECT barcode,name FROM product_list WHERE code = 'TT003' OR  code = 'TT002'";
            sqlDataSource.CommandTimeout = 0;

            this.reportViewer.ReportSource = typeReportSouce;
            this.reportViewer.RefreshReport();
        }

1 Answer, 1 is accepted

Sort by
0
박문석
Top achievements
Rank 1
answered on 05 Mar 2020, 02:48 AM

I found a solution by my self.

        private void reportViewer1_Load(object sender, EventArgs e)
        {

            SqlDataSource sqlDataSource = new SqlDataSource();
            sqlDataSource.ProviderName = "MySql.Data.MySqlClient";
            sqlDataSource.ConnectionString = "Server=****;Port=****;Database=****;Uid=****;Pwd=****;CharSet=utf8;Convert Zero Datetime=True";
            sqlDataSource.SelectCommand = "SELECT barcode,name FROM product_list WHERE code = 'TT006' OR  code = 'TT008' ORDER BY code";
            sqlDataSource.CommandTimeout = 0;

            BarcodePrintReport barcodePrintReport = new BarcodePrintReport();
            barcodePrintReport.ReportParameters.Add("barcode", ReportParameterType.String, "04321");
            barcodePrintReport.DataSource = sqlDataSource;

            var instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = barcodePrintReport;

            this.reportViewer.ReportSource = instanceReportSource;
            this.reportViewer.RefreshReport();

}

Tags
General Discussions
Asked by
박문석
Top achievements
Rank 1
Answers by
박문석
Top achievements
Rank 1
Share this question
or