使用已声明的数据集的Datagrid视图到Crystal报表 [英] Datagrid view to crystal reports using declared dataset
本文介绍了使用已声明的数据集的Datagrid视图到Crystal报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
暗报告 As 新 CrystalReport1
Dim ds As 新建数据集
' 从datagridview中获取数据和结构,并将其作为数据集返回.您可以使用
在项目/类顶部的' 导入System.Data"声明,并删除system.data
' 此函数各个部分中的内容.
尝试
' 向数据集添加新表
ds.Tables.Add(" )
' 添加列
Dim col As DataColumn
' 为datagridveiw中的每个列在表中添加新列
对于 每个 dgvCol As DataGridViewColumn 位于中的ProductsDataGridView.Columns
col = 新建 DataColumn(dgvCol.Name)
ds.Tables(" ).Columns.Add(col)
下一步
' 从datagridview添加行
Dim 行 As DataRow
Dim 帐户 As 整数 = ProductsDataGridView.Columns .Count- 1
对于 i As 整数 = 0 到 ProductsDataGridView.Rows.Count- 1
row = ds.Tables(" ).
对于 每个列 As DataGridViewColumn 位于中的ProductsDataGridView.Columns
row.Item(column.Index)= ProductsDataGridView.Rows.Item(i).Cells(column.Index).Value
下一步
下一步
捕获,例如 As 异常
' 捕获所有潜在错误并将其显示给用户
MessageBox.Show(" & ex.InnerException.ToString,_
" ,MessageBoxButtons.OK,MessageBoxIcon.错误)
结束 尝试
report.SetDataSource(ds.Tables( 0 ))
CrystalReportViewer1.ReportSource =报告
Form2.Show()
Form2.DataGridView1.DataSource = ds.Tables( 0 )
ds.Dispose()
ds = 没什么
解决方案
尝试并看了 ^ ]:
热门链接:
链接1 [链接2 [链接3 [使用其功能组,图形,交叉表和子报表逐步创建Crystal报表 [^ ]
您好,但是由于某种原因,无法使代码从datagridview中显示数字数据,它仅传递字符串信息,并且不显示数字字段,请帮助我. thanxs
在项目中添加数据集
添加>新项目>数据集
创建数据集列,紧随其后的是DataGridColumnNames:)
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
解决方案
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[^]
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
Add A Dataset in your Project
ADD > New Item > Dataset
Create the Dataset Columns followed on your DataGridColumnNames :)
这篇关于使用已声明的数据集的Datagrid视图到Crystal报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文