Tuesday, February 2, 2010

filling the dataset in the report

Filling the dataset in the report
--------------------------------
string constr = ConfigurationManager.ConnectionStrings["Reports"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd = new SqlCommand("CrossTab", con);
ReportDocument rpt = new ReportDocument();

SqlDataAdapter adap = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

try
{

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@StartDate", SqlDbType.VarChar).Value = DateTime.Parse(txtProjectStartDt.Text, new CultureInfo("en-GB")).ToString("d", new CultureInfo("en-US"));
cmd.Parameters.Add("@Enddate", SqlDbType.VarChar).Value = DateTime.Parse(txtProjectEndDt.Text, new CultureInfo("en-GB")).ToString("d", new CultureInfo("en-US"));

adap.Fill(ds, "Orders");

if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
rpt.Load(Server.MapPath("CR.rpt"));
rpt.SetDataSource(ds.Tables[0]);

crvCrossTab.ReportSource = rpt;
crvCrossTab.DataBind();
crvCrossTab.Visible = true;
}
else
{
Response.Write("No Record Exist");
crvCrossTab.Visible = false;
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();

con = null;


}

No comments:

Post a Comment