Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
i have this code that reflects datagrid values in crystal reports by using datasets. i commit error "The Report Has no Tables" thx in advance
 
Dim report As New CrystalReport1
       Dim ds As New DataSet
 

       'Take the data and structure from the datagridview and return it as a dataset.  You can use
       '"Imports System.Data" declaration at the top of your project/class and remove the system.data
       'from the various parts of this function.

       Try
           'Add a new table to the dataset
           ds.Tables.Add("Main")
 
           'Add the columns
           Dim col As DataColumn
 
           'For each colum in the datagridveiw add a new column to your table
           For Each dgvCol As DataGridViewColumn In ProductsDataGridView.Columns
               col = New DataColumn(dgvCol.Name)
               ds.Tables("Main").Columns.Add(col)
           Next
 
           'Add the rows from the datagridview
           Dim row As DataRow
           Dim colcount As Integer = ProductsDataGridView.Columns.Count - 1
 
           For i As Integer = 0 To ProductsDataGridView.Rows.Count - 1
               row = ds.Tables("Main").Rows.Add
 
               For Each column As DataGridViewColumn In ProductsDataGridView.Columns
                   row.Item(column.Index) = ProductsDataGridView.Rows.Item(i).Cells(column.Index).Value
               Next
 
           Next
 

       Catch ex As Exception
           'Catch any potential errors and display them to the user
           MessageBox.Show("Error Converting from DataGridView" & ex.InnerException.ToString, _
           "Error Converting from DataGridView", MessageBoxButtons.OK, MessageBoxIcon.Error)
 
       End Try
 
       report.SetDataSource(ds.Tables(0))
       CrystalReportViewer1.ReportSource = report
 
       Form2.Show()
       Form2.DataGridView1.DataSource = ds.Tables(0)
       ds.Dispose()
       ds = Nothing
Posted 13-Apr-11 5:28am
Edited 13-Apr-11 5:46am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Tried and looked here[^]:
Top few links:
Link 1[^]
Link 2[^]
Link 3[^]
 
BTW, check your implementation with this article. It does not looks correct: Step by Step Creation of Crystal Report using its Features Group, Graph, Cross-Tab and Sub Report[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hey men great job, but for some reason a can't make the code shows the numeric data form the datagridview, it only passes the string info and the numeric fields are not displayed, please help me. thanxs
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Add A Dataset in your Project
 
ADD > New Item > Dataset
 
Create the Dataset Columns followed on your DataGridColumnNames Smile | :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 574
1 OriginalGriff 373
2 Damith Weerasinghe 355
3 thatraja 350
4 Abhinav S 230
0 Sergey Alexandrovich Kryukov 10,639
1 OriginalGriff 6,658
2 Peter Leow 4,735
3 Abhinav S 3,813
4 Maciej Los 3,565


Advertise | Privacy | Mobile
Web04 | 2.8.140421.2 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid