数据库中的存储过程是
ALTER proc UTC_GetMingxiBaobiao
(
@UTC_MingXi_Cust varchar(50),
@UTC_MingXi_State int,
@UTC_MingXi_date varchar(20),
@UTC_MingXi_Accuser varchar(30)
)
as
select h.UTCid,h.PhoneNo,h.CustCode,h.CustName,convert(varchar(10),h.Rectime,120) as Rectime,
h.Flag,convert(varchar(10),h.Acctime,120) as Acctime,h.Accuser,d.ArtCode,d.Quantity,a.ArtName
from utc_header as h join utc_detail as d
on(h.UTCid = d.UTCid) join utc_article as a
on(d.artcode=a.artcode)
where (@UTC_MingXi_Cust is null or CustCode = @UTC_MingXi_Cust)
and (@UTC_MingXi_State=3 or Flag = @UTC_MingXi_State)
and (@UTC_MingXi_date is null or @UTC_MingXi_date = convert(varchar(10),Acctime,120))
and (@UTC_MingXi_Accuser ='ALL' or Accuser = @UTC_MingXi_Accuser)
程序代码是
protected void Button1_Click(object sender, EventArgs e)
{ SqlParameter[] workParam = new SqlParameter[4];
workParam[0] = new SqlParameter("@UTC_MingXi_Cust", SqlDbType.NVarChar);
workParam[0].Direction = ParameterDirection.Input;
workParam[0].Value = "350944"; workParam[1] = new SqlParameter("@UTC_MingXi_State", SqlDbType.Int);
workParam[1].Direction = ParameterDirection.Input;
workParam[1].Value = 3; workParam[2] = new SqlParameter("@UTC_MingXi_date", SqlDbType.NVarChar);
workParam[2].Direction = ParameterDirection.Input;
workParam[2].Value = "2009-05-07"; workParam[3] = new SqlParameter("@UTC_MingXi_Accuser", SqlDbType.NVarChar);
workParam[3].Direction = ParameterDirection.Input;
workParam[3].Value = "萧山清点员";
DataSet ds = new DataSet();
DataBaseM DBM = new DataBaseM();
ds = DBM.RunProc("UTC_GetMingxiBaobiao", workParam, ds); if (ds.Tables[0].Rows.Count == 0)// 执行这一句
{
Response.Redirect("Nodata.aspx");
}
ReportViewer1.Visible = true; ReportDataSource rds = new ReportDataSource("DataSetmingxi_UTC_GetMingxiBaobiao", ds.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.Refresh();在查分器中执行
exec UTC_GetMingxiBaobiao '35044',3,'2009-05-07','萧山清点员' 有数据返回
ALTER proc UTC_GetMingxiBaobiao
(
@UTC_MingXi_Cust varchar(50),
@UTC_MingXi_State int,
@UTC_MingXi_date varchar(20),
@UTC_MingXi_Accuser varchar(30)
)
as
select h.UTCid,h.PhoneNo,h.CustCode,h.CustName,convert(varchar(10),h.Rectime,120) as Rectime,
h.Flag,convert(varchar(10),h.Acctime,120) as Acctime,h.Accuser,d.ArtCode,d.Quantity,a.ArtName
from utc_header as h join utc_detail as d
on(h.UTCid = d.UTCid) join utc_article as a
on(d.artcode=a.artcode)
where (@UTC_MingXi_Cust is null or CustCode = @UTC_MingXi_Cust)
and (@UTC_MingXi_State=3 or Flag = @UTC_MingXi_State)
and (@UTC_MingXi_date is null or @UTC_MingXi_date = convert(varchar(10),Acctime,120))
and (@UTC_MingXi_Accuser ='ALL' or Accuser = @UTC_MingXi_Accuser)
程序代码是
protected void Button1_Click(object sender, EventArgs e)
{ SqlParameter[] workParam = new SqlParameter[4];
workParam[0] = new SqlParameter("@UTC_MingXi_Cust", SqlDbType.NVarChar);
workParam[0].Direction = ParameterDirection.Input;
workParam[0].Value = "350944"; workParam[1] = new SqlParameter("@UTC_MingXi_State", SqlDbType.Int);
workParam[1].Direction = ParameterDirection.Input;
workParam[1].Value = 3; workParam[2] = new SqlParameter("@UTC_MingXi_date", SqlDbType.NVarChar);
workParam[2].Direction = ParameterDirection.Input;
workParam[2].Value = "2009-05-07"; workParam[3] = new SqlParameter("@UTC_MingXi_Accuser", SqlDbType.NVarChar);
workParam[3].Direction = ParameterDirection.Input;
workParam[3].Value = "萧山清点员";
DataSet ds = new DataSet();
DataBaseM DBM = new DataBaseM();
ds = DBM.RunProc("UTC_GetMingxiBaobiao", workParam, ds); if (ds.Tables[0].Rows.Count == 0)// 执行这一句
{
Response.Redirect("Nodata.aspx");
}
ReportViewer1.Visible = true; ReportDataSource rds = new ReportDataSource("DataSetmingxi_UTC_GetMingxiBaobiao", ds.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.Refresh();在查分器中执行
exec UTC_GetMingxiBaobiao '35044',3,'2009-05-07','萧山清点员' 有数据返回
{
SqlCommand Cmd = CreateCmd(procName, prams);
SqlDataAdapter Da = new SqlDataAdapter(Cmd);
try
{
Da.Fill(Ds);
}
catch (Exception Ex)
{
throw Ex;
}
return Ds;
}
public SqlCommand CreateCmd(string procName, SqlParameter[] prams)
{
SqlConnection Conn;
Conn = new SqlConnection(ConnStr);
Conn.Open();
SqlCommand Cmd = new SqlCommand(procName, Conn);
Cmd.CommandType = CommandType.StoredProcedure;
if (prams != null)
{
foreach (SqlParameter parameter in prams)
{
if (parameter != null)
{
Cmd.Parameters.Add(parameter);
}
}
}
return Cmd;
}
SET NOCOUNT ON;--这里加这一句~~~
select h.UTCid,h.PhoneNo,h.CustCode,h.CustName,convert(varchar(10),h.Rectime,120) as Rectime,