locked
Bind Datagridview to ReportView RRS feed

  • Question

  • I would like to bind a DatagridView to Reportviewer by code. I have followed the following  steps.

    1) With try......Catch.......end try

     Dim sqlConnection1 As New SqlConnection("Data Source=FRANCISCOXPS27\FRANCISCO;Initial Catalog=Modelling;Integrated Security=True")
                    Dim cmd As New SqlCommand
                    Dim reader As SqlDataReader
                    'SENTENCIA SQL
                    cmd.CommandText = "SELECT Name_Account  , V2006, V2007,  V2008, V2009, V2010, V2011, V2012, V2013   FROM Aer_Lingus_Financial_Position_VERTICAL_1_View Where ID LIKE   '[3]%'   "
                    cmd.CommandType = CommandType.Text
                    cmd.Connection = sqlConnection1
                    sqlConnection1.Open()
                    cmd = New SqlCommand(cmd.CommandText, sqlConnection1)
                    reader = cmd.ExecuteReader()
                    Dim da As New SqlDataAdapter(cmd)
                    Dim ds As New DataSet
                    reader.Close()
                    da.Fill(ds)
                    DataGridView4.DataSource = ds.Tables(0)

    This code retrieve the data from SQL

    2) DatagridView  to Reportviewer

    I am using this code

         Dim Rds As New ReportDataSource("Dataset1", "Aer_Lingus_Financial_Position_HistoricDataGridView")
    
            ReportViewer1.LocalReport.DataSources.Add(Rds)
    
            Me.ReportViewer1.RefreshReport()

    The end result is nothing, and I would like to know solve it by code or to know which is my error

    Thank you in advance




    • Edited by Frank0401 Friday, February 6, 2015 11:09 AM
    Friday, February 6, 2015 11:05 AM

Answers

  • This doesn't make much sense to me.

    1.  why the datareader it does nothing

    2. the constructor for reportdatasource  = Name, datasource/ienumerable/object

         you use 2 strings in your constructor,

    try

    Dim Rds As New ReportDataSource(ds.Tables(0).TableName , ds.Tables(0))

    and remove the datareader part in your code


    • Edited by Rbie Friday, February 6, 2015 12:52 PM
    • Marked as answer by Carl Cai Sunday, February 15, 2015 2:29 AM
    Friday, February 6, 2015 12:50 PM