无需使用for循环即可将数据从dataGridView传输到Crystal Report [英] Transfering data from dataGridView to Crystal Report without using a for loop

查看:67
本文介绍了无需使用for循环即可将数据从dataGridView传输到Crystal Report的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在下面有一个工作代码,它使用数据集将数据从dataGridView传输到Crystal Report。我使用for循环遍历dataGridView Rows。问题是,当我在dataGridView上有太多数据,并且我运行此代码时,我会遇到闪烁效果,并且需要很长时间才能完成填充报表。我的问题是,这是因为for循环而发生的。有没有办法可以在不使用for循环的情况下将数据传输到水晶报表,也可以更好地解决我的闪烁和时间问题?

提前感谢您提供的任何帮助。

这是我的代码

 DataSet4 ds =  new  DataSet4(); 
DataTable t = ds.Tables.Add( stock);
t.Columns.Add( Item_Name,Type.GetType( System.String));
t.Columns.Add( Store,Type.GetType( System.String));
t.Columns.Add( Total_Stock,Type.GetType( System.String));
t.Columns.Add( Product_Code,Type.GetType( System.String));


DataRow r;

string ItemName = string .Empty;
string sto = string .Empty;
string totostok = string .Empty;
string pcode = string .Empty;


for int i = 0 ; i < dataGridView1.RowCount; i ++)
{
pcode = dataGridView1.Rows [i ] .Cells [ 0 ]。Value.ToString();
ItemName = dataGridView1.Rows [i] .Cells [ 1 ]。Value.ToString();
sto = dataGridView1.Rows [i] .Cells [ 2 ]。Value.ToString();
totostok = dataGridView1.Rows [i] .Cells [ 3 ]。Value.ToString();


r = t.NewRow();
r [ Product_Code] = pcode;
r [ Item_Name] = ItemName;
r [ Store] = sto;
r [ Total_Stock] = totostok;

t.Rows.Add(r);

CrystalReport4 objRpt = new CrystalReport4();
objRpt.SetDataSource(ds.Tables [ 1 ]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Dock = DockStyle.Fill;
crystalReportViewer1.Refresh();
crystalReportViewer1.Show();
}

解决方案

你可以使用数据集从datagrdview传输数据



定义一个可以从datagridview更新数据的数据集



将crystalreport数据源设置为该数据集


< blockquote>这是它

首先你将使用ado.net工具将很容易为你

添加新数据集来自

项目添加新的项目

然后将你的Colums添加到\在你的解决方案目录中创建的dataSet



然后如果你有一个datagridView设置来自的数据源您创建的数据集的数据集\

现在在水晶报表中,您需要指定数据源,这将是您的数据集



in button_click将生成你的报告写下这些代码



dataSet11.AcceptChanges();



CrystalRepo rt1 objRpt = new CrystalReport1();

objRpt.SetDataSource(dataSet11.Tables [0]);

crystalReportViewer1.ReportSource = objRpt;

 





无需更多代码



完整源代码示例

下载此解决方案

http://yourcodes.info/attachments/crystalreport .zip [ ^ ]

$ / b $ b



你好兄弟b 
$ bi已录制视频给你看看你怎么做这个从链接下载视频

i希望这解决你的问题



< a href = www.yourcodes.info/crystal.wmv > 下载视频< / a >

最好的问候


你好兄弟



i已录制视频供您查看如何从链接下载视频< br $>


i希望这能解决你的问题







下载视频



最好的问候


Hi,
I have a working code below that transfers data from a dataGridView to a Crystal Report using a dataset. Am using for loop to loop through dataGridView Rows. Problem is that when i have too much data on the dataGridView, and i run this code, i experience a flickering effect and it takes such a long time to finish populating the report. My quess is that, that happens because of the for loop. Is there a way i can transfer the data to crystal report without using a for loop or maybe a better solution to my flickering and time taken problem??
Thanks in advance for any help granted.
Here is my code

DataSet4 ds = new DataSet4();
DataTable t = ds.Tables.Add("stock");
t.Columns.Add("Item_Name", Type.GetType("System.String"));
t.Columns.Add("Store", Type.GetType("System.String"));
t.Columns.Add("Total_Stock", Type.GetType("System.String"));
t.Columns.Add("Product_Code", Type.GetType("System.String"));


DataRow r;

string ItemName = string.Empty;
string sto = string.Empty;
string totostok = string.Empty;
string pcode = string.Empty;


for (int i = 0; i < dataGridView1.RowCount; i++)
{
    pcode = dataGridView1.Rows[i].Cells[0].Value.ToString();
    ItemName = dataGridView1.Rows[i].Cells[1].Value.ToString();
    sto = dataGridView1.Rows[i].Cells[2].Value.ToString();
    totostok = dataGridView1.Rows[i].Cells[3].Value.ToString();


    r = t.NewRow();
    r["Product_Code"] = pcode;
    r["Item_Name"] = ItemName;
    r["Store"] = sto;
    r["Total_Stock"] = totostok;

    t.Rows.Add(r);

    CrystalReport4 objRpt = new CrystalReport4();
    objRpt.SetDataSource(ds.Tables[1]);
    crystalReportViewer1.ReportSource = objRpt;
    crystalReportViewer1.Dock = DockStyle.Fill;
    crystalReportViewer1.Refresh();
    crystalReportViewer1.Show();
}

解决方案

you can allways transfer data from datagrdview using dataset

define a dataset the can update data from datagridview

the set the crystalreport datasource to that dataset


this is it
first you will work with ado.net tools will be easy for you
add new Dataset from
project Add New Item
Then Add Your Colums To \The dataSet Created In your solution Directory

Then If You Hhave A datagridView Set The Datasource From The peoperies to the dataset you created\
now in the crystal report you will need to specify the datasource which will be your dataset

in the button_click which will generate your report write these code

dataSet11.AcceptChanges();

CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(dataSet11.Tables[0]);
crystalReportViewer1.ReportSource = objRpt;



no further code needed

full source example
download this solution
http://yourcodes.info/attachments/crystalreport.zip[^]



hello bro

i  have recorded video for you to see how you can do this download the video from the link

i hope this solves your problem



<a href="www.yourcodes.info/crystal.wmv">download video</a>

Best Regards


hello bro

i have recorded video for you to see how you can do this download the video from the link

i hope this solves your problem



download video

Best Regards


这篇关于无需使用for循环即可将数据从dataGridView传输到Crystal Report的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆