水晶报表同ACCESS数据库连接问题

jiefy 2010-12-15 05:09:31
各位高手, 我想做一个这样的程序

数据库 ACCESS dbuser
数据表 user
字段
用户姓名 UserName
用户年龄 userage
居住地址 address 字段

用c# winform

1 窗口
textbox button
进行 参数输入 ,点击按钮 搜索 用户姓名

通过 用户姓名 这个参数 将 用户的信息 传递 给 水晶报表 在窗口2中显示出来

2窗口 获得1 窗口传递过来的参数 将 用户的信息 包括 姓名 年龄 地址 显示出来 并能打印。

如何实现。我是新手,希望能说的详细点。谢谢!!!
...全文
221 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiefy 2011-01-04
  • 打赏
  • 举报
回复
感谢 各位的回答。尤其是版主的一些教程对我很有帮助。
原来链接是用数据专家里德 新建链接。直接链接数据库。用的绝对路径。并且这个方法 好像不是push方法。因为调用的代码不执行。而且当换机器后会提示输入数据库密码。从网上也找了很多的帖子。但是没有什么好的办法。于是还是改用push方法。直接用dataset 链接。用 ado 方法里链接的。这样就能克服绝对路径的问题。
感谢各位的关注。不过好像图表区的热度不是很高。
jiefy 2010-12-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 babyt 的回复:]
ReportDocument myReport = new ReportDocument();
//string reportPath = System.Web.HttpContext.Current.Server.MapPath("bin/debug/CrystalReport1.rpt");
//你的rpt文件没load进来吧?
//myReport.Load(reportPat……
[/Quote]

string reportPath = System.Web.HttpContext.Current.Server.MapPath("CrystalReport1.rpt");
myReport.Load(reportPath);
将这个运行 提示

System.NullReferenceException: 未将对象引用设置到对象的实例。
这个是什么原因啊??

luohui368 2010-12-17
  • 打赏
  • 举报
回复
hao sdoij af
Aro0223 2010-12-17
  • 打赏
  • 举报
回复
myReport.SetDataSource(ds1);
这里没有指定具体的表
myReport.SetDataSource(ds1.table("AppUser"))
阿泰 2010-12-16
  • 打赏
  • 举报
回复
这是个报表的基本需求,不过对于刚接触一个新的报表工具的朋友来说,确实可能有些无从下手的感觉

1:首先了解下,怎么做一个基本的水晶报表,对于Access数据源,建议使用PUSH模式
【水晶报表内功心法】--PUSH模式样板招式 [推荐]
2:在上一篇文章的基础上,实现参数过滤。

【水晶报表内功心法】--数据过滤 [推荐]
阿泰 2010-12-16
  • 打赏
  • 举报
回复
ReportDocument myReport = new ReportDocument();
//string reportPath = System.Web.HttpContext.Current.Server.MapPath("bin/debug/CrystalReport1.rpt");
//你的rpt文件没load进来吧?
//myReport.Load(reportPath);

myReport.SetDataSource(ds1);
crystalReportViewer1.ReportSource = myReport;
jiefy 2010-12-16
  • 打赏
  • 举报
回复
非常感谢 阿泰 版主的回复。
我按照您的方法做了,但是我不是用的 web方式
用的 winform 方式。
我想是一样的。
但是 我做了以后 过滤出来的数据显示不出来啊。不知道是哪里出了错。

第一个 winform 上我一个 textbox 定义name 为 BianH 一个 botton 当 botton click的时候 运行

private void button1_Click(object sender, EventArgs e)
{
string BianH = this.BianH.Text;
Form ShowBianH = new ShowBianH(BianH );
ShowBianH .ShowDialog();
}
第二 个 winform 上 我添加了一个 crystalReportViewer1
代码这样写的。
public partial class ShowBianH : Form
{
public ShowBianH(string BianH)
{
string a = BianH;
InitializeComponent();
label1.Text = a;
}

private void ShowBianH_Load(object sender, EventArgs e)
{
string b = label1.Text;
DataSet1 ds1 = new DataSet1();
OleDbDataAdapter da = new OleDbDataAdapter();
string conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e_record.mdb";//;Data Source=path; Jet OLEDB:Database Password=pwd;//
OleDbConnection con = new OleDbConnection(conStr);

da = new OleDbDataAdapter("SELECT RegName as RegName,IdType as IdType,BianH as BianH,LandNum as LandNum From AppUser", con);
da.Fill(ds1, "AppUser");

//da = new OleDbDataAdapter("select BianH as BianH,AddDate as AddDate From Land_Case where BianH=" + "'" + b + "'" + "", con);
//da.Fill(ds1, "Land_Case");

//da = new OleDbDataAdapter("select LandNum as LandNum,LandAddress as LandAddress From TLand where BianH=" + "'" + b + "'" + "", con);
//da.Fill(ds1, "TLand");

//da = new OleDbDataAdapter("select Csyj as Csyj From Shyj where BianH=" + "'" + b + "'" + "", con);
//da.Fill(ds1, "Shyj");
ReportDocument myReport = new ReportDocument();
//string reportPath = System.Web.HttpContext.Current.Server.MapPath("bin/debug/CrystalReport1.rpt");
//myReport.Load(reportPath);

myReport.SetDataSource(ds1);
crystalReportViewer1.ReportSource = myReport;
}
}

运行的时候 具体数据不显示出来。。不知道什么原因啊。?
Aro0223 2010-12-15
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20090626/17/8090bf70-bed9-41ac-9e09-c0a6a7ab4cb8.html
你这个很简单,去看看泰哥写的,看完后你自己就能做出来

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧