经常有网友问这个问题,长时间不看自己也忘记了,今天又碰到一个网友提问,没辙,花了点下班时间把几个步骤记录如下,请指正!
1、新建一个windows application:cristaltest;
2、新添加一个数据集dataset1.xsd
3、在dataset1里添加表datatable1
在datatable1里添加四列column1,column2,column3,column4 ,保存
4、添加一个水晶报表文件crystalreport1.rpt
设置数据源:项目数据(project data)-->ado.net datasets-->***.dataset1-->datatable1
5、把column1,column2,column3,column4拖到水晶报表的细节(details)中
6、添加一个控件crystalreportviewer1到form1中
7、然后添加form1_load的代码
dim m_sqlconn as sqlconnection
dim m_strsqlconn as string
m_strsqlconn = "data source=localhost; initial catalog=pubs;user id=sa;password="
m_sqlconn = new sqlconnection(m_strsqlconn)
try
dim sqladp as sqldataadapter
dim strsql as string
dim ds = new dataset()
m_sqlconn.open()
strsql = "select au_lname as column1, au_fname as column2, phone as column3, address as column4 from dbo.authors"
sqladp = new sqldataadapter(strsql, m_sqlconn)
sqladp.fill(ds)
dim crreportdocument = new crystalreport1()
crreportdocument.setdatasource(ds.tables(0))
crystalreportviewer1.reportsource = crreportdocument
catch ex as exception
messagebox.show(ex.tostring())
end try
8、在form1.vb文件头加
imports system.data
imports system.data.sqlclient
9、 m_strsqlconn = "data source=localhost; initial catalog=pubs;user id=sa;password="这个可能要修改成你的机器的sql server连接信息
新闻热点
疑难解答
图片精选