如何在运行时为C#中的Windows Forms Report指定数据库路径 [英] How to specify database path at run time for Windows Forms Report in C#

查看:99
本文介绍了如何在运行时为C#中的Windows Forms Report指定数据库路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在VS2008下使用Microsoft Report Viewer.
我在报告[Windows窗体应用程序]时遇到以下问题

1.
我可以在不使用任何DataSet.xsd文件的情况下进行报告吗?
2.
我如何在运行时为报表指定数据库路径,因为它将在用户计算机上更改.我不想将其存储在.config或任何文件的连接字符串中.另外ConnectionString包含数据库的密码.
3.
对于5个报表,我认为表单上的单个报表查看器控件将执行此操作,并且将需要5个不同的.rdlc文件,
但是我需要创建多少个DataSet.xsd文件? [如果使用].
4.
我创建了一个Dataset1.xsd文件,添加了一个表适配器,
启动配置向导,然后我跟随整个过程,编写查询&完成等.
但是它要求存储连接字符串……我不想要它.
如果我不存储如何实现报表功能?
我创建了DataSet1.xsd文件,只是为了在Report1.rdlc上绘制字段,所以我想忘记这一点.
我使用以下代码在运行时显示报告.

Hello every One,
I am using Microsoft Report Viewer under VS2008.
I have following problems in reporting [ Windows Forms Application]

1.
Can I make reports without using any DataSet.xsd file ?
2.
How can I specify database path at run time for reports, because it will change on user''s computer. I don''t want to store it in connection string in .config or any file. Also ConnectionString contains password for database.
3.
For 5 Reports I think single report viewer control on a form will do this, and 5 different .rdlc files will be required ,
but how many DataSet.xsd files do I need to create? [If I use].
4.
I created one Dataset1.xsd file, added one Table adapter ,
That started configuration wizard then I followed whole thing, wrote query & Finish etc.
But it asks to store connection string ...... I don''t want it.
If I don''t store how to achieve Reporting?
I created DataSet1.xsd file , just to draw fields on Report1.rdlc , then I want to forget this.
I use following code to show report at run time.

private void button1_Click(object sender, EventArgs e)
{
    SqlCeConnection con=new SqlCeConnection("Data Source=" +
    Global.MyAppPath + @"\Database\CityPride.sdf;password=xyz");
    con.Open();
    DataSet ds=new DataSet("login"); // probably any string
    SqlCeDataAdapter da=new SqlCeDataAdapter ("select * from login",con);

    da.Fill(ds,"Login"); // why should I need to give table name Login here , if                                    I already mentioned it in query, may be I will need data from multiple tables then?

    ReportDataSource rds = new ReportDataSource();
    rds.Name = "login"; // probably any string
    rds.Value = ds.Tables[0];
    reportViewer1.LocalReport.ReportPath = "..\\..\\Reports\\Report1.rdlc";
    reportViewer1.LocalReport.DataSources.Clear();
    reportViewer1.LocalReport.DataSources.Add(rds);
    reportViewer1.Refresh();
    reportViewer1.RefreshReport();
}

不起作用是什么问题?
它给出了错误:-
尚未为数据源DataSet1_Login
提供数据源实例
请帮助,谢谢.

[edit]已添加代码块-OriginalGriff [/edit]

Does not work what is wrong?
It gives error:-
a data source instance has not been supplied for the data source DataSet1_Login

Please Help, Thanks.

[edit]Code block added - OriginalGriff[/edit]

推荐答案

"da.Fill(ds,"Login")行中您的问题注释的答案是数据集可能包含多个表.代表SqlDataAdapter的"da"仅用于将DataTables添加到数据集,它与查询完全没有关系.

在查询中,您可以根据需要使用多个表,但是在此之前,您必须通过SqlDataAdapter将所有表添加到数据集中.
The answer for your question comment in line "da.Fill(ds, "Login"); is that a dataset may contain multiple tables. And your ''da'' that represents to SqlDataAdapter works to just add DataTables to dataset, its not related to your query any way.

In your query you can use multiple table as you asked but before that you have to add all tables to dataset through SqlDataAdapter.


1.-您需要一个DataSet来将每个归档的表绑定到报表.
2.-
1.- You need a DataSet to bind each filed to the report.
2.-
reportViewer1.LocalReport.ReportPath = strYourPath;

您//您可以在运行时更改它,必须使用一个变量.
3.-如果所有报告完全不同,则是的,您需要每个数据集来绑定每个报告.
4.-设计中只需要使用Visual Studio加载数据就需要连接字符串.您正在使用rdlc文件,这意味着您将在服务器中处理报告.
如果您使用usr rdl文件,则需要在客户端中处理报告,在这种情况下,您将需要直接传递数据集.

http://www.gotreportviewer.com/ [ ^ ]

you //You could change this in runtime, you have to use a variable.
3.- If all the reports are totally different, yes you need each DataSet to bind each Report.
4.- The connection string is requiered in the design just to load data with VisualStudio. You are using rdlc files that means that you are going to process your report in a Server.
If you usr rdl files you will need to process your reports in your Client, in this case you''ll need to pass the DataSet directly.

http://www.gotreportviewer.com/[^]


这篇关于如何在运行时为C#中的Windows Forms Report指定数据库路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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