VS2010 水晶报表的使用方法
打开app.config文件,在“startup”节点一个“uselegacyv2runtimeactivationpolicy="true"”属性
<startup uselegacyv2runtimeactivationpolicy="true">
<supportedruntime version="v4.0" sku=".netframework,version=v4.0"/>
</startup>
在form1窗体中,从工具箱拖出一个crystal report viewer控件,双击form窗体,是双击form窗体,不是crystal report viewer,在后台的form_load事件中写入如下代码:
private void form1_load(object sender, eventargs e)
{
string connstr = "data source=.\\sqlexpress;initial catalog=dbtest;user id=sa;password=test";
sqlconnection conn = new sqlconnection(connstr);
conn.open();
try
{
string sql = "select * from customer where email!='test@gmail.com'";
sqldataadapter sda = new sqldataadapter(sql, conn);
dataset ds = new dataset();
sda.fill(ds, "tmptable");
string reportpath = system.windows.forms.application.startuppath + @"\crystalreport1.rpt";
reportdocument rd = new reportdocument();
rd.load(reportpath);
rd.setdatasource(ds.tables[0].defaultview);
this.crystalreportviewer1.reportsource = rd;
}
catch (exception ex)
{
throw new exception(ex.message.tostring());
}
finally
{
conn.close();
}
}
这样就ok了
上一篇: JavaWeb利用邮箱帮用户找回密码
下一篇: java多线程编程技术详解和实例代码