获取“数据库登录错误"导航下一页时在 Crystal Report 中

Getting quot;Database Logon Errorquot; in Crystal Report While Navigating Next Page(获取“数据库登录错误导航下一页时在 Crystal Report 中)
本文介绍了获取“数据库登录错误"导航下一页时在 Crystal Report 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ASP.NET 和 C#(数据集)中为 Crystal Report 开发了以下代码,我在报告中有多个页面,我正确地获得了第一页,但是在导航下一页时,我遇到了登录错误.

I have Developed Below Code for Crystal Report in ASP.NET and C# (Dataset), I have Multiple Pages in report i am getting 1st page Properly but while Navigating next page i am getting logon error.

public partial class WSDayBookReport : System.Web.UI.Page
{
    SQLClass sqlfunc = new SQLClass();
    DayBookDataSet dset = new DayBookDataSet();
    ReportDocument rdoc;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Page_Unload(object sender, EventArgs e)
{
    try
    {
        rdoc.Close();
        rdoc.Dispose();
        rdoc = null;
    }
    catch (Exception ex)
    {
    }
}
public void OpeningStock()
{
    string qry = "select  i.ItemGroupID, ig.ItemGroupCode As ItemGroupCode, Sum(iss.RegularStock) As OpeningStock from ItemStock iss, Item i, ItemGroup ig where ig.ItemGroupID = i.ItemGroupID AND iss.ItemID = i.ItemId group by i.ItemGroupID,ig.ItemGroupCode";
    sqlfunc.GetDataFromDT(dset.ItemGroupStock, qry, "sqlcon");
    var q1 = from igs in dset.ItemGroupStock.AsEnumerable()
             select igs;
    foreach (var res in q1)
    {
        res.ConsumedStock = 0;
        res.ClosingStock = 0;
    }
    dset.AcceptChanges();
    //Response.Write(dset.ItemGroupStock.Rows.Count.ToString() + "=Opening Stock");
}
public void loadUser()
{
    string qry = "select pp.PersonnelParticularID As UserID, pp.PersonnelName As UserName from WineOrder wo, WineOrderDetail wod, PersonnelParticular pp, ItemGroup ig, Item i where pp.PersonnelParticularID = wo.IssuedToPersonnelID AND ig.ItemGroupID = i.ItemGroupID AND i.ItemID = wod.ItemID AND wod.IsOrderCancelled = 0 AND wod.WineOrderId = wo.WineOrderId AND wo.WineOrderDate ='" + Convert.ToDateTime(txtDate.Text).ToString("MM/dd/yyyy") + "' group by pp.PersonnelParticularID,pp.PersonnelName";
    sqlfunc.GetDataFromDT(dset.UserMaster, qry, "sqlcon");
    qry = "select  pp.PersonnelParticularID As UserID,ig.ItemGroupID, sum(wod.OrderQty) As ConsumptionQty from WineOrder wo, WineOrderDetail wod, ItemGroup ig, Item i, PersonnelParticular pp where pp.PersonnelParticularID = wo.IssuedToPersonnelID AND ig.ItemGroupID = i.ItemGroupID AND i.ItemID = wod.ItemID AND wod.IsOrderCancelled = 0 AND wod.WineOrderId = wo.WineOrderId AND wo.WineOrderDate='" + Convert.ToDateTime(txtDate.Text).ToString("MM/dd/yyyy") + "' group by ig.ItemGroupID, pp.PersonnelParticularID";
    sqlfunc.GetDataFromDT(dset.UserConsume, qry, "sqlcon");
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
    dset = new DayBookDataSet();
    OpeningStock();
    loadUser();
    //Deducting new RU Entry after the entered date...
    DataTable dtTemp = new DataTable();
    string qry2 = "select Sum(rs.Quantity) As Qty,i.ItemGroupID from RegularStock rs, Item i where i.ItemID = rs.ItemID AND rs.RSDate>='" + Convert.ToDateTime(txtDate.Text).ToString("MM/dd/yyyy") + "' Group by i.ItemGroupID";
    sqlfunc.GetDataFromDT(dtTemp, qry2, "sqlcon");
    if (dtTemp.Rows.Count > 0)
    {
        for (int i = 0; i < dtTemp.Rows.Count; i++)
        {
            var q5 = from igs in dset.ItemGroupStock.AsEnumerable()
                     where igs.ItemGroupID == Convert.ToInt32(dtTemp.Rows[i][1].ToString())
                     select igs;
            foreach (var res in q5)
            {
                res.OpeningStock -= Convert.ToDecimal(dtTemp.Rows[i][0].ToString());
            }
        }
    }
    //Adding cosumed stock from the entered date.
    dtTemp = new DataTable();
    string qry = "select  ig.ItemGroupID, sum(wod.OrderQty) As ConsumptionQty from WineOrder wo, WineOrderDetail wod, ItemGroup ig, Item i where ig.ItemGroupID = i.ItemGroupID AND i.ItemID = wod.ItemID AND wo.IssuedToPersonnelID is not null AND wod.IsOrderCancelled = 0 AND wod.WineOrderId = wo.WineOrderId AND wo.WineOrderDate>='10-01-2015' group by ig.ItemGroupID";
    sqlfunc.GetDataFromDT(dtTemp, qry, "sqlcon");
    if (dtTemp.Rows.Count > 0)
    {
        for (int i = 0; i < dtTemp.Rows.Count; i++)
        {
            var q5 = from igs in dset.ItemGroupStock.AsEnumerable()
                     where igs.ItemGroupID == Convert.ToInt32(dtTemp.Rows[i][0].ToString())
                     select igs;
            foreach (var res in q5)
            {
                res.OpeningStock += Convert.ToDecimal(dtTemp.Rows[i][1].ToString());
            }
        }
    }
    dset.AcceptChanges();
    var qry10 = from us in dset.UserConsume.AsEnumerable()
                group us by us.ItemGroupID into g
                select new
                {
                    TOTAL = g.Sum(x => x.ConsumptionQty),
                    IG = g.Key
                };
    foreach (var res in qry10)
    {
        //Response.Write(res.IG.ToString() +"-"+res.TOTAL.ToString()+ "----------");
        var qrry = from igs in dset.ItemGroupStock.AsEnumerable()
                   where igs.ItemGroupID == res.IG
                   select igs;
        foreach (var res2 in qrry)
        {
            res2.ClosingStock = res2.OpeningStock - res.TOTAL;
        }
    }
    rdoc = new ReportDocument();
    rdoc.Load(Server.MapPath("~/Report/WSDayBookRpt.rpt"));
    rdoc.SetDataSource(dset);
    CrystalReportViewer1.DataBind();
    CrystalReportViewer1.ReportSource = rdoc;
    CrystalReportViewer1.RefreshReport();
}
}

请帮帮我..我曾尝试使用会话,但在第二页之后我无法导航,如果我使用写页码进行导航,它可以正常工作......

Please Help me out .. i have tried using session but in that i am not able to navigate after 2nd Page and if i use to write page number for navigation its working properly...

感谢和问候,

更新

public partial class WSDayBookReport : System.Web.UI.Page

{
    SQLClass sqlfunc = new SQLClass();
    ReportDocument rdoc = new ReportDocument();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            if (Session["CRpt"] != null)
            {
                rdoc =(ReportDocument) Session["CRpt"];
            }
            CrystalReportViewer1.ReportSource = rdoc;
            CrystalReportViewer1.RefreshReport();
        }
        else
        {
            // 'NOT POSTBACK
        }
    }

    protected void Page_Unload(object sender, EventArgs e)
    {
        if (Session["CRpt"] != null)
        {
            Session.Remove("CRpt");
        }
        Session["CRpt"]=rdoc;
    }

protected void btnSubmit_Click(object sender, EventArgs e)
{
    DayBookDataSet dset = new DayBookDataSet();
    //OpeningStock();
    string qry = "select  i.ItemGroupID, ig.ItemGroupCode As ItemGroupCode, Sum(iss.RegularStock) As OpeningStock from ItemStock iss, Item i, ItemGroup ig where ig.ItemGroupID = i.ItemGroupID AND iss.ItemID = i.ItemId group by i.ItemGroupID,ig.ItemGroupCode";
    sqlfunc.GetDataFromDT(dset.ItemGroupStock, qry, "sqlcon");
    var q1 = from igs in dset.ItemGroupStock.AsEnumerable()
             select igs;
    foreach (var res in q1)
    {
        res.ConsumedStock = 0;
        res.ClosingStock = 0;
    }
    // loadUser();
    qry = "select pp.PersonnelParticularID As UserID, pp.PersonnelName As UserName from WineOrder wo, WineOrderDetail wod, PersonnelParticular pp, ItemGroup ig, Item i where pp.PersonnelParticularID = wo.IssuedToPersonnelID AND ig.ItemGroupID = i.ItemGroupID AND i.ItemID = wod.ItemID AND wod.IsOrderCancelled = 0 AND wod.WineOrderId = wo.WineOrderId AND wo.WineOrderDate='" + Convert.ToDateTime(txtDate.Text).ToString("MM/dd/yyyy") + "' group by pp.PersonnelParticularID,pp.PersonnelName";
    sqlfunc.GetDataFromDT(dset.UserMaster, qry, "sqlcon");
    if (dset.UserMaster.Rows.Count == 0)
    {
        lblStatus.Text = "No Consumption on selected date.";
        CrystalReportViewer1.ReportSource = null;
        if (Session["ssnRdoc"] != null)
        {
            Session.Remove("ssnRdoc");
        }

        return;
    }
    else
    {
        lblStatus.Text = "";
    }

    //user consumption
    qry = "select  pp.PersonnelParticularID As UserID,ig.ItemGroupID, sum(wod.OrderQty) As ConsumptionQty from WineOrder wo, WineOrderDetail wod, ItemGroup ig, Item i, PersonnelParticular pp where pp.PersonnelParticularID = wo.IssuedToPersonnelID AND ig.ItemGroupID = i.ItemGroupID AND i.ItemID = wod.ItemID AND wod.IsOrderCancelled = 0 AND wod.WineOrderId = wo.WineOrderId AND wo.WineOrderDate='" + Convert.ToDateTime(txtDate.Text).ToString("MM/dd/yyyy") + "' group by ig.ItemGroupID, pp.PersonnelParticularID";
    sqlfunc.GetDataFromDT(dset.UserConsume, qry, "sqlcon");
    dset.AcceptChanges();
    ViewState.Add("vsDset", dset);
    //Deducting new RU Entry after the entered date...
    DataTable dtTemp = new DataTable();
    string qry2 = "select Sum(rs.Quantity) As Qty,i.ItemGroupID from RegularStock rs, Item i where i.ItemID = rs.ItemID AND rs.RSDate>='" + Convert.ToDateTime(txtDate.Text).ToString("MM/dd/yyyy") + "' Group by i.ItemGroupID";
    sqlfunc.GetDataFromDT(dtTemp, qry2, "sqlcon");
    if (dtTemp.Rows.Count > 0)
    {
        for (int i = 0; i < dtTemp.Rows.Count; i++)
        {
            var q5 = from igs in dset.ItemGroupStock.AsEnumerable()
                     where igs.ItemGroupID == Convert.ToInt32(dtTemp.Rows[i][1].ToString())
                     select igs;
            foreach (var res in q5)
            {
                res.OpeningStock -= Convert.ToDecimal(dtTemp.Rows[i][0].ToString());
            }
        }
    }
    //Adding cosumed stock from the entered date.
    dtTemp = new DataTable();
    qry = "select  ig.ItemGroupID, sum(wod.OrderQty) As ConsumptionQty from WineOrder wo, WineOrderDetail wod, ItemGroup ig, Item i where ig.ItemGroupID = i.ItemGroupID AND i.ItemID = wod.ItemID AND wo.IssuedToPersonnelID is not null AND wod.IsOrderCancelled = 0 AND wod.WineOrderId = wo.WineOrderId AND wo.WineOrderDate>='" + Convert.ToDateTime(txtDate.Text.Trim()).ToString("MM/dd/yyyy") + "' group by ig.ItemGroupID";
    sqlfunc.GetDataFromDT(dtTemp, qry, "sqlcon");
    if (dtTemp.Rows.Count > 0)
    {
        for (int i = 0; i < dtTemp.Rows.Count; i++)
        {
            var q5 = from igs in dset.ItemGroupStock.AsEnumerable()
                     where igs.ItemGroupID == Convert.ToInt32(dtTemp.Rows[i][0].ToString())
                     select igs;
            foreach (var res in q5)
            {
                res.OpeningStock += Convert.ToDecimal(dtTemp.Rows[i][1].ToString());
            }
        }
    }
    dset.AcceptChanges();
    var qry10 = from us in dset.UserConsume.AsEnumerable()
                group us by us.ItemGroupID into g
                select new
                {
                    TOTAL = g.Sum(x => x.ConsumptionQty),
                    IG = g.Key
                };
    foreach (var res in qry10)
    {
        var qrry = from igs in dset.ItemGroupStock.AsEnumerable()
                   where igs.ItemGroupID == res.IG
                   select igs;
        foreach (var res2 in qrry)
        {
            res2.ClosingStock = res2.OpeningStock - res.TOTAL;
        }
    }
    ViewState.Add("vsDset", dset);
    rdoc.Load(Server.MapPath("~/Report/WSDayBookRpt.rpt"));
    rdoc.SetDataSource(dset);
    CrystalReportViewer1.DataBind();
    CrystalReportViewer1.ReportSource = rdoc;
    CrystalReportViewer1.RefreshReport();
    Session["CRpt"]= rdoc;
}
}

推荐答案

您的 CrystalReportViewer 控件可能在 PostBack 上丢失了 ReportDocument.您必须按以下方式进行操作:

Your CrystalReportViewer control is probably loosing the ReportDocument on PostBack. You will have to do it as follows:

在页面级别声明您的 ReportDocument 对象

Declare your ReportDocument object at page level

ReportDocument rdoc = new ReportDocument();

在 Page_Load 事件中,从 Session 对象加载您的 ReportDocument

In the Page_Load event load your ReportDocument from Session object

protected void Page_Load(System.Object sender, System.EventArgs e) {
    if (Page.IsPostBack) {
        if (Session.Item("CRpt") != null) {
            rdoc = Session.Item("CRpt");
        }
        CrystalReportViewer1.ReportSource = rdoc;
        CrystalReportViewer1.RefreshReport();
    } else {
        'NOT POSTBACK
        if (Session.Item("CRpt") != null) {
            Session.Remove("CRpt");
        }
        Session.Add("CRpt", rdoc);
    }
}

在 btnSubmit 上创建 ReportDocument 并将其添加到 Session

On the btnSubmit create and add your ReportDocument to Session

protected void btnSubmit_Click(object sender, EventArgs e) {

    //Populate Report 
    rdoc.SetDataSource(dset);
    CrystalReportViewer1.ReportSource = rdoc;
    Session.Add("CRpt", rdoc);
}

除此之外,如果您在设置 LogOnInfo 时需要特定帮助,那么您还可以查看此 SO 帖子 报告在将 DataTable 设置为时要求数据库登录数据源

Besides this if you need specific help in setting LogOnInfo then you may also check this SO post Report asking for database login on setting DataTable as DataSource

这篇关于获取“数据库登录错误"导航下一页时在 Crystal Report 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)