Popular Posts

Jul 25, 2013

Get data to crystal report using storeprocedure (ASP.NET)



Create Storeprocedure:


    ALTER PROCEDURE billDetails
    /*
    (
    @parameter1 int = 5,
    @parameter2 datatype OUTPUT
    )
    */
    @billno varchar(10)
AS
BEGIN

select orderid,bookid,bookname,quantity,price,totalprice,sc.billnumber,name,contact,shipaddress,amount FROM ShoppingCart as sc Inner Join PaymentDetails as pd ON sc.billnumber = pd.billnumber WHERE billnumber=@billno

END
    /* SET NOCOUNT ON */
    RETURN



Code Behind:

SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\Proj\BookStore.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
    DataSet ds = new DataSet();
    SqlDataAdapter adp;
    public static string billnum;
    store ss1 = new store();

    protected void Page_Load(object sender, EventArgs e)
    {
        ss1 = Session["data2"] as store;
        billnum = ss1.bino;
        LoginName ln = (LoginName)Master.FindControl("LoginName1");
        adp = new SqlDataAdapter("EXEC billDetailsOne @billno= " + billnum, conn);
        adp.Fill(ds, "billDetailsOne");
        ReportDocument report = new ReportDocument();
        string reportpath = Server.MapPath("CrystalReport.rpt");
        report.Load(reportpath);
        report.SetDataSource(ds.Tables["billDetailsOne"]);
        CrystalReportViewer1.ReportSource = report;
    }

No comments:

Post a Comment