想疯了(一个报表显示问题)在线等
crtDay oRpt = new crtDay();
string strSql = "select s.Code,s.Name,o.OnDutyDay,o.UpPassTime,(select datename(weekday, ' "+sDate+ " ') )as WeekDate,o.OffPassTime,o.LateDuty,o.EarlyDuty,o.Abnormity,o.OT from tblStaff as s,tblOnDutyNote as o where s.Code=o.StaffID and o.OnDutyDay= ' " + sDate + " ' ";
DataSet ds = null;
string ErrMessage = " ";
if (DBAccess.ExecSql(strSql, ref ds, ref ErrMessage) == 0)
{
//oRpt.Load(Application.StartupPath + " crtDay1.rpt ");
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string weekDate = null;
weekDate = ds.Tables[0].Rows[i][ "WeekDate "].ToString();
//string[] arry = new string[7] { "Moday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday ", "Sunday "};
switch (weekDate)
{
case "Moday ":
weekDate = "星期一 ";
break;
case "Tuesday ":
weekDate = "星期二 ";
break;
case "Wednesday ":
weekDate = "星期三 ";
break;
case "Thursday ":
weekDate = "星期四 ";
break;
case "Friday ":
weekDate = "星期五 ";
break;
case "Saturday ":
weekDate = "星期六 ";
break;
case "Sunday ":
weekDate = "星期天 ";
break;
default:
weekDate = ds.Tables[0].Rows[i][ "WeekDate "].ToString();
break;
}
int Abnormity=0;
string abnormity = null;
switch(Abnormity)
{
case 0:
abnormity = "正常 ";
break;
case 1:
abnormity = "迟到 ";
break;
case 2:
abnormity = "早退 ";
break;
default:
abnormity = "正常 ";
break;
}
string OnDutyDay = Convert.ToDateTime(ds.Tables[0].Rows[i][ "OnDutyDay "]).ToShortDateString();
//DateTime UpPassTime = Convert.ToDateTime(ds.Tables[0].Rows[i][ "UpPassTime "]).ToLongTimeString();
//DateTime OffPassTime = Convert.ToDateTime(ds.Tables[0].Rows[i][ "OffPassTime "]).ToLongTimeString();
oRpt.ParameterFields[ "职工工号 "].CurrentValues.AddValue(ds.Tables[0].Rows[i][ "Code "].ToString());
oRpt.ParameterFields[ "职工姓名 "].CurrentValues.AddValue(ds.Tables[0].Rows[i][ "Name "].ToString());
oRpt.ParameterFields[ "日期 "].CurrentValues.AddValue(OnDutyDay.ToString());
oRpt.ParameterFields[ "星期 "].CurrentValues.AddValue(weekDate);
oRpt.ParameterFields[ "进时间 "].CurrentValues.AddValue(ds.Tables[0].Rows[i][ "UpPassTime "].ToString());
oRpt.ParameterFields[ "出时间 "].CurrentValues.AddValue(ds.Tables[0].Rows[i][ "OffPassTime "].ToString());
oRpt.ParameterFields[ "迟到时间 "].CurrentValues.AddValue(ds.Tables[0].Rows[i][ "LateDuty "].ToString());
oRpt.ParameterFields[ "早退时间 "].CurrentValues.AddValue(ds.Tables[0].Rows[i][ "EarlyDuty "].ToString());
oRpt.ParameterFields[ "状态 "].CurrentValues.AddValue(abnormity);
oRpt.ParameterFields[ "加班 "].CurrentValues.AddValue(ds.Tables[0].Rows[i][ "OT "].ToString());
//oRpt.SetDataSource(ds);
}
this.crystalReportViewer1.ReportSource = oRpt;
}
else
{
this.crystalReportViewer1.Visible = false;
}
}
//首先从数据库中能查出3条记录:
但是现在问题是循环3次后报表上只是显示第一条记录
不知道什么原因
有谁知道吗
[解决办法]
在本地建立一个DataTable 让后把数据循环的读入这个DataTable中,然后把这个DataTable
放入一个DataSet中,在绑定给报表
难道你没有用.xsd么?
为什么要用参数字段啊!
[解决办法]
dp.CommandText = "SELECT * WHERE (c.FBaseInfoID = @FBaseInfoID) ";//定义查询
dp.Parameter.Add( "FBaseInfoID ",user.userID);
DataSet ds1 = dp.DataSetSQL();//将查询结果返回到DataSet中
R_C102 R_D_C102 = new R_C102(); //定义报表事例控件用于绑定数据,没创建一个报表文件就是创建了一个报表文件类
R_D_C102.SetDataSource(ds1); //将数据(ds1)绑定到报表文件上
CrystalReportViewer1.ReportSource = R_D_C102;
CrystalReportViewer1.DataBind();
--------------------------------
如果你想改变 ds1的Table中的值你循环变例修改就可以了
例如
for(int i=0;i <ds1.Tables[0].rows.count;i++)
{
if (ds1.Tables[0].rows[i][ "星期 "].tostring() == 1)
{
ds1.Tables[0].rows[i][ "星期 "]= "星期一 ";
}
....
}