我通过这段代码绑定了我的水晶报表,但是不知道在水晶报表里的公式字段该怎么设置,求助:
求问怎么把数据集添加进水晶报表,并设置公式字段
DataSet ds = workingDayAccess.GetAbsentDays(workingDays, Convert.ToDateTime(StartTime.Text),Convert.ToDateTime(EndTime.Text));
CrystalReport1 cs1 = new CrystalReport1();
cs1.Load(Server.MapPath("CrystalReport1.rpt"));
cs1.SetDataSource(ds.Tables["AbsentDays"]);
Report1.ReportSource = cs1;
Report1.DataBind();
Report1.Visible = true;在CrystalReport1.rpt中该怎么做?
求问怎么把数据集添加进水晶报表,并设置公式字段
DataSet ds = workingDayAccess.GetAbsentDays(workingDays, Convert.ToDateTime(StartTime.Text),Convert.ToDateTime(EndTime.Text));
CrystalReport1 cs1 = new CrystalReport1();
cs1.Load(Server.MapPath("CrystalReport1.rpt"));
cs1.SetDataSource(ds.Tables["AbsentDays"]);
Report1.ReportSource = cs1;
Report1.DataBind();
Report1.Visible = true;在CrystalReport1.rpt中该怎么做?
解决方案 »
- 『100分』C#连接Access数据偶尔出错 求建立连接时完整的connString格式
- 关于SESSION丢失后自动跳转到主页
- 求一个C#客户端服务器程序
- 今天忧闷无比,发一问贴,望各位版友支持下
- DataGrid 的列名在左侧显示 而非默认的在最上方显示 可以实现吗? 请大侠指点迷津
- 弹出对话框问题
- picturebox中如何正确显示imagelist中已有的图像?
- 我怎么知道事件是否已加了
- 高手们请教一个WINDOW 应用程序问题,
- 关于ListView和集合的问题!!!大家想个好办法!
- 关于c#的一个问题
- public All<Money> getIn2010(Work harder):base(2009){}
把数据填充到dataset
把datatable绑定到水晶报表
CrystalReport1 cs1 = new CrystalReport1();
cs1.Load(Server.MapPath("CrystalReport1.rpt"));
cs1.SetDataSource(ds.Tables["AbsentDays"]);
Report1.ReportSource = cs1;
Report1.DataBind();
Report1.Visible = true;
就是运行的时候数据没有显示出来
现在看,貌似是个白板,里面啥也没有?,呵呵请参考本文之操作方法,照着做一下,很快有感觉
《【水晶报表内功心法】--PUSH模式样板招式 》
DataSet ds=new DataSet();
你添加一个dataset控件dataset1;
里面生成一个 datatable1(列数和类型和数据库要显示的字段的类型一致);
dataset1 ds1=new dataset();
sqladapter.fill(ds1);
Report1.ReportSource = ds1.Tables[0];
参考
http://topic.csdn.net/u/20090713/18/6e14bf28-1979-4ade-9c60-aaf09284553d.html中的2:WebForm开发的一个重要技巧:小代码,大作用 这一节。
OleDbParameter workingDays = new OleDbParameter("workingDate", SqlDbType.DateTime);
workingDays.Value = workdingDay;
OleDbParameter start = new OleDbParameter("SysDate", SqlDbType.DateTime);
start.Value = startTime;
OleDbParameter end = new OleDbParameter("SysDate", SqlDbType.DateTime);
end.Value = endTime;
OleDbCommand cmd = new OleDbCommand(getAbsentDays, conn);
cmd.Parameters.Add(workingDays);
cmd.Parameters.Add(start);
cmd.Parameters.Add(end); OleDbDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
int fieldCount = dr.FieldCount;
for (int i = 0; i < fieldCount; i++)
{
dt.Columns.Add(dr.GetName(i), dr.GetFieldType(i));
}
object[] objValues = new object[fieldCount];
while (dr.Read())
{
dr.GetValues(objValues);
dt.LoadDataRow(objValues, true);
}
dr.Close();
dt.EndLoadData() ; DataSet1 ds = new DataSet1();
ds.Tables.Add(dt); ReportDocument cs1 = new ReportDocument();
cs1.Load(Server.MapPath("CrystalReport1.rpt"));
cs1.SetDataSource(ds.Tables["AbsentDays"]);
Report1.ReportSource = cs1;
Report1.DataBind();
这样写有问题么,怎么还出那个dataset的验证
检查你设计报表是的dataset里的表,表名称和字段及类型,与你程序里传递进去的是否一致。
<xs:schema id="DataSet1" targetNamespace="http://tempuri.org/DataSet1.xsd" xmlns:mstns="http://tempuri.org/DataSet1.xsd" xmlns="http://tempuri.org/DataSet1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:annotation>
<xs:appinfo source="urn:schemas-microsoft-com:xml-msdatasource">
<DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<Connections />
<Tables />
<Sources />
</DataSource>
</xs:appinfo>
</xs:annotation>
<xs:element name="DataSet1" msdata:IsDataSet="true" msdata:UseCurrentLocale="true" msprop:Generator_UserDSName="DataSet1" msprop:Generator_DataSetName="DataSet1" msprop:EnableTableAdapterManager="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="AbsentDays" msprop:Generator_UserTableName="AbsentDays" msprop:Generator_RowDeletedName="AbsentDaysRowDeleted" msprop:Generator_RowChangedName="AbsentDaysRowChanged" msprop:Generator_RowClassName="AbsentDaysRow" msprop:Generator_RowChangingName="AbsentDaysRowChanging" msprop:Generator_RowEvArgName="AbsentDaysRowChangeEvent" msprop:Generator_RowEvHandlerName="AbsentDaysRowChangeEventHandler" msprop:Generator_TableClassName="AbsentDaysDataTable" msprop:Generator_TableVarName="tableAbsentDays" msprop:Generator_RowDeletingName="AbsentDaysRowDeleting" msprop:Generator_TablePropName="AbsentDays">
<xs:complexType>
<xs:sequence>
<xs:element name="EmpId" msprop:Generator_UserColumnName="EmpId" msprop:Generator_ColumnVarNameInTable="columnEmpId" msprop:Generator_ColumnPropNameInRow="EmpId" msprop:Generator_ColumnPropNameInTable="EmpIdColumn" type="xs:int" minOccurs="0" />
<xs:element name="EmpName" msprop:Generator_UserColumnName="EmpName" msprop:Generator_ColumnVarNameInTable="columnEmpName" msprop:Generator_ColumnPropNameInRow="EmpName" msprop:Generator_ColumnPropNameInTable="EmpNameColumn" type="xs:string" minOccurs="0" />
<xs:element name="Absent" msprop:Generator_UserColumnName="Absent" msprop:Generator_ColumnVarNameInTable="columnAbsent" msprop:Generator_ColumnPropNameInRow="Absent" msprop:Generator_ColumnPropNameInTable="AbsentColumn" type="xs:int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>dataset的代码
//加上一句
dt.TableName="AbsentDays";
Report1.DataBind(); 注释掉看看
DataTable dtAbsentDay = ds.Tables["AbsentDays"]; object[] objValues = new object[dr.FieldCount];
while (dr.Read())
{
dr.GetValues(objValues);
dtAbsentDay.LoadDataRow(objValues,true);
}
dr.Close();
GridView1.DataSource = dtAbsentDay;
GridView1.DataBind(); ReportDocument cs1 = new ReportDocument();
cs1.Load(Server.MapPath("CrystalReport1.rpt"));
cs1.SetDataSource(ds);
Report1.ReportSource = cs1;
这是我现在的code,已经没有你说的那两个了,但是问题还没有解决
ReportDocument cs1 = new ReportDocument();
cs1.Load(Server.MapPath("CrystalReport1.rpt"));
cs1.SetDataSource(ds);
Report1.ReportSource = cs1;
这是绑定的过程
<CR:CrystalReportViewer ID="Report1" runat="server" AutoDataBind="True"
Height="1039px" Width="901px" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="CrystalReport1.rpt"></Report>
</CR:CrystalReportSource>
这个是界面的代码,我是新手,第一次接触水晶,今天弄这个弄了一天,没搞定
如果出问题的话,我感觉很有可能就是出在绑定这块了