数据集未读取值 [英] DataSet Not Reading values

查看:87
本文介绍了数据集未读取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在我的项目中生成rdlc报告.这里的数据集不从数据库中读取值.但是,当我执行Sql查询值时.P
租赁帮助我解决此问题.

这是我的代码:

Hi Everyone,

I am generating a rdlc report in my project. Here dataset not reading values from database. But when I execute Sql query values are coming.P
lease help me to fix this issue.

Here is My Code:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Microsoft.Reporting.WebForms;
using System.Data.SqlClient;
using Microsoft.VisualBasic;

public partial class InvRep : System.Web.UI.Page
{
    EMS ems = new EMS();
    string con = ConfigurationManager.ConnectionStrings["constr"].ToString();


    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            if (!IsPostBack)
            {

                SqlCommand cmd = new SqlCommand("spGettblInvoiceReport");
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@invno", SqlDbType.Int).Value = Convert.ToInt16(Request.QueryString["invno"]);
                cmd.Parameters.Add("@companyid", SqlDbType.Int).Value = Convert.ToInt16(Session["companyid"].ToString());
                DataSet dsInv = ems.Make_Ds(cmd, con);

                SqlCommand cmd1 = new SqlCommand("spGetTblInvoicedetailsReport");
                cmd1.CommandType = CommandType.StoredProcedure;
                cmd1.Parameters.Add("@invno", SqlDbType.Int).Value = Convert.ToInt16(Request.QueryString["invno"]);
                cmd1.Parameters.Add("@companyId", SqlDbType.Int).Value = Convert.ToInt16(Session["companyid"].ToString());


                DataSet dsPRD = ems.Make_Ds(cmd1, con);

                DataSet dsPRD1 = new DataSet();
                dsPRD1.Tables.Add("dtinvoicedetails");

                dsPRD1.Tables[0].Columns.Add("catalogno");
                dsPRD1.Tables[0].Columns.Add("itemcode");
                dsPRD1.Tables[0].Columns.Add("unit");
                dsPRD1.Tables[0].Columns.Add("qty");
                dsPRD1.Tables[0].Columns.Add("rate");
                dsPRD1.Tables[0].Columns.Add("value");
                dsPRD1.Tables[0].Columns.Add("datacolumn1");
                dsPRD1.Tables[0].Columns.Add("serialnos");
                dsPRD1.Tables[0].Columns.Add("partno");

                dsPRD1.Tables[0].Columns.Add("itemno");


                SqlCommand cmd2 = new SqlCommand("spGetTblInvoiceTaxReport");
                cmd2.CommandType = CommandType.StoredProcedure;
                cmd2.Parameters.Add("@invno", SqlDbType.Int).Value = Convert.ToInt16(Request.QueryString["invno"]);
                cmd2.Parameters.Add("@companyid", SqlDbType.Int).Value = Convert.ToInt16(Session["companyid"].ToString());
                DataSet dsTax = ems.Make_Ds(cmd2, con);


                DataSet dsmm = new DataSet();
                dsmm.Tables.Add(dsInv.Tables[0].Copy());
                dsmm.Tables[0].TableName = "tblInvoiceReport";



                for (int z = 0; z < dsPRD.Tables[0].Rows.Count; z++)
                {
                    SqlCommand prdcmd = new SqlCommand("spGetTblProductDetCatlog");
                    prdcmd.CommandType = CommandType.StoredProcedure;
                    prdcmd.Parameters.Add("@catalogno", SqlDbType.VarChar).Value = dsPRD.Tables[0].Rows[z]["catalogno"].ToString();
                    DataSet ds = ems.Make_Ds(prdcmd, con);
                    string catalogItems = "";
                    string serialnos = "";
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        string fldId = ds.Tables[0].Rows[0]["featureid"].ToString();
                        string lvlname = ems.ShowLvlName(fldId, con);
                        string getsql = "select " + lvlname.Replace(" ", "") + "make,originalprice from classtransactionnew where productdesc='" + dsPRD.Tables[0].Rows[z]["catalogno"].ToString() + "'";
                        string[] items = lvlname.Split(',');
                        int i;
                        DataSet getds = new DataSet();
                        for (i = 0; i < Information.UBound(items, 1); i++)
                        {

                            //lbl1.Text = items[i].ToString();


                            SqlConnection conn = ems.Open_Connection(con);
                            SqlDataAdapter da = new SqlDataAdapter(getsql, conn);

                            da.Fill(getds);

                            SqlCommand cmdtab = new SqlCommand("spGetTableNameDescr");
                            cmdtab.CommandType = CommandType.StoredProcedure;
                            cmdtab.Parameters.Add("@tname", SqlDbType.VarChar).Value = items[i].Replace(" ", "").ToString();
                            cmdtab.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt16(getds.Tables[0].Rows[0][items[i].Replace(" ", "")]);
                            string descr = Convert.ToString(ems.Get_SqlValue(cmdtab, con));
                            //lbl2.Text = descr;

                            if (items[i].Replace(" ", "").ToUpper().ToString() == "MODELNUMBER")
                            {
                                catalogItems += descr + Environment.NewLine;
                            }
                            else
                            {

                                catalogItems += items[i].ToString() + ":" + descr + ",";
                            }
                        }

                        DataRow dr1 = dsPRD1.Tables[0].NewRow();
                        dr1[0] = dsPRD.Tables[0].Rows[z]["catalogno"].ToString();
                        dr1[1] = dsPRD.Tables[0].Rows[z]["itemcode"].ToString();
                        dr1[2] = dsPRD.Tables[0].Rows[z]["unit"].ToString();
                        dr1[3] = dsPRD.Tables[0].Rows[z]["qty"].ToString();
                        dr1[4] = dsPRD.Tables[0].Rows[z]["rate"].ToString();
                        dr1[5] = dsPRD.Tables[0].Rows[z]["value"].ToString();
                        //if(dsPRD.Tables[0].Rows[z]["serialnos"].ToString()!="")
                        // serialnos="Valve Sl No. :"+dsPRD.Tables[0].Rows[z]["serialnos"].ToString();
                        dr1[6] = "Model No:" + dsPRD.Tables[0].Rows[z]["catalogno"].ToString() + Environment.NewLine + catalogItems.Substring(0, catalogItems.Length - 1) + Environment.NewLine + serialnos;
                        dr1[7] = dsPRD.Tables[0].Rows[z]["serialnos"].ToString();
                        dr1[8] = dsPRD.Tables[0].Rows[z]["partno"].ToString();
                        dr1[9] = ++z;
                        dsPRD1.Tables[0].Rows.Add(dr1);


                    }
                }

                dsmm.Tables.Add(dsPRD1.Tables[0].Copy());

                dsmm.Tables[1].TableName = "tblInvoiceDetails";

                dsmm.Tables.Add(dsTax.Tables[0].Copy());
                dsmm.Tables[2].TableName = "tblInvoiceTax";


                dsmm.WriteXmlSchema("InvRep.xsd"); // proper dataset xsd file namePurchaseRequest_TblPr
                //ReportDataSource datasource = new ReportDataSource("PurchaseRequest_tblpr", dsmm.Tables[0]);
                ReportDataSource datasource = new ReportDataSource("InvRep_tblInvoiceReport", dsmm.Tables[0]);//proper datasetname
                ReportDataSource datasource1 = new ReportDataSource("InvRep_tblInvoiceDetails", dsmm.Tables[1]);//proper datasetname
                ReportDataSource datasource2 = new ReportDataSource("InvRep_tblInvoiceTax", dsmm.Tables[2]);
                ReportViewer.LocalReport.DataSources.Clear();
                ReportViewer.LocalReport.DataSources.Add(datasource);
                ReportViewer.LocalReport.DataSources.Add(datasource1);
                ReportViewer.LocalReport.DataSources.Add(datasource2);
                ReportViewer.LocalReport.ReportPath = Server.MapPath("Reports//InvRep1.rdlc");
                if (dsmm.Tables[0].Rows.Count == 0)
                {
                    Response.Write("Sorry, no Data under this category!");
                }

                
                ReportViewer.LocalReport.Refresh();
            }

        }
        catch (SqlException sqlex)
        {

            Logger.Log("Error while Binding data " + sqlex.Message + " Stack Trace: " + sqlex.StackTrace, LogLevel.ERROR);
        }
    }
    protected void lnkback_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["dash"] != null)
        {
            Response.Redirect("Customerrep.aspx");
        }
        else if (Request.QueryString["dash"] == null)
        {
            Response.Redirect("Invoice.aspx");
        }
    }
    protected void logout_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("index.aspx");
    }
 }

推荐答案



请注意,您没有在程序中打开连接.更新以下代码

SqlConnection conn =新的SqlConnection(con);
conn.Open();
SqlCommand cmd =新的SqlCommand("spGettblInvoiceReport");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ invno",SqlDbType.Int).Value = Convert.ToInt16(Request.QueryString ["invno"]);
cmd.Parameters.Add("@ companyid",SqlDbType.Int).Value = Convert.ToInt16(Session ["companyid"].ToString());
数据集dsInv = ems.Make_Ds(cmd,conn);

SqlCommand cmd1 =新的SqlCommand("spGetTblInvoicedetailsReport");
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add("@ invno",SqlDbType.Int).Value = Convert.ToInt16(Request.QueryString ["invno"]);
cmd1.Parameters.Add("@ companyId",SqlDbType.Int).Value = Convert.ToInt16(Session ["companyid"].ToString());
数据集dsPRD = ems.Make_Ds(cmd1,conn);

而且你的衣着很不好.您正在使用查询字符串和会话中的值,但是甚至不检查空值.
您的功能不应该这么大.

请按照下面的链接获取编码标准.

http://www.tiobe.com/content/paperinfo/gemrcsharpcs.pdf [ ^ ]
Hi,

Please note that you are not opening connection in your program. Update the below code

SqlConnection conn = new SqlConnection(con);
conn.Open();
SqlCommand cmd = new SqlCommand("spGettblInvoiceReport");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@invno", SqlDbType.Int).Value = Convert.ToInt16(Request.QueryString["invno"]);
cmd.Parameters.Add("@companyid", SqlDbType.Int).Value = Convert.ToInt16(Session["companyid"].ToString());
DataSet dsInv = ems.Make_Ds(cmd, conn);

SqlCommand cmd1 = new SqlCommand("spGetTblInvoicedetailsReport");
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add("@invno", SqlDbType.Int).Value = Convert.ToInt16(Request.QueryString["invno"]);
cmd1.Parameters.Add("@companyId", SqlDbType.Int).Value = Convert.ToInt16(Session["companyid"].ToString());
DataSet dsPRD = ems.Make_Ds(cmd1, conn);

And your coading is very bad. You are using values from query string and session but even not checking for null values.
Your function should not be this big.

Follow the below link for coading standard.

http://www.tiobe.com/content/paperinfo/gemrcsharpcs.pdf[^]


我是使用此代码打开连接.(AppCode)
EMS ems =新的EMS();
字符串con = ConfigurationManager.ConnectionStrings ["constr"].ToString();
I am opening connection using this code.(AppCode)
EMS ems = new EMS();
string con = ConfigurationManager.ConnectionStrings["constr"].ToString();


这篇关于数据集未读取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆