Object引用对象的实例 [英] Object Reference to an instance of an object

查看:64
本文介绍了Object引用对象的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有方法gridbind,如下所示给出对象引用错误

所以请任何好友告诉我它为什么会出错。

I have method gridbind which is shown below which is giving object reference error
so please any buddy tell me why it is giving error.

public void Gridbind()
{
    StringBuilder var1 = new StringBuilder();
    var1.Append("SELECT tblpullsms.ID,Row_number() \n");
    var1.Append("         OVER ( \n");
    var1.Append("           ORDER BY tblpullsms.createddate DESC)           AS SrNo, \n");
    var1.Append("       fm.factoryname                                      AS FactoryName, \n");
    var1.Append("       ec.enumerationvalue                                 AS FactoryType, \n");
    var1.Append("       CONVERT(VARCHAR(10), tblpullsms.createddate, 103)   AS CreatedDate, \n");
    var1.Append("       tblpullsms.mobileno, \n");
    var1.Append("       CONVERT(VARCHAR(10), tblpullsms.createddate, 103) \n");
    var1.Append("       + '  ' \n");
    var1.Append("       + CONVERT(VARCHAR(10), tblpullsms.createddate, 108) AS CreatedDate1, \n");
    var1.Append("       cd.districtname, \n");
    var1.Append("       tblpullsms.code, \n");
    var1.Append("       Sum(tblpullsms.crush)                               AS Crush, \n");
    var1.Append("       Sum(tblpullsms.prod)                                AS Prod, \n");
    var1.Append("       Sum(tblpullsms.rate)                                AS Rate, \n");
    var1.Append("       Cast(Avg(tblpullsms.recov) AS NUMERIC(18, 2))       AS Recov, \n");
    var1.Append("       ev.enumerationvalue                                 AS Division \n");
    var1.Append("FROM   dbo.tblpullsms \n");
    var1.Append("       INNER JOIN factory_master fm \n");
    var1.Append("               ON fm.factorycode = tblpullsms.code \n");
    var1.Append("       INNER JOIN enumerationvalue ec \n");
    var1.Append("               ON ec.enumerationvalueid = fm.factorytype \n");
    var1.Append("       INNER JOIN census_district cd \n");
    var1.Append("               ON cd.districtcode = fm.districtid \n");
    var1.Append("       INNER JOIN enumerationvalue ev \n");
    var1.Append("               ON ev.enumerationvalueid = cd.divisionid \n");
    var1.Append("WHERE  cd.langid = 1 \n");
    var1.Append("       AND tblpullsms.isactive = 1 \n");
    var1.Append("       AND CONVERT(varchar(10), tblpullsms.createddate, 120) = convert(varchar(10),GetDate(),120) \n");
    var1.Append("GROUP  BY fm.factoryname, \n");
    var1.Append("          cd.districtname, \n");
    var1.Append("          tblpullsms.code, \n");
    var1.Append("          tblpullsms.createddate, \n");
    var1.Append("          ev.enumerationvalue, \n");
    var1.Append("          ec.enumerationvalue, \n");
    var1.Append("          tblpullsms.mobileno, \n");
    var1.Append("          tblpullsms.crush, \n");
    var1.Append("          tblpullsms.prod, \n");
    var1.Append("          tblpullsms.rate, \n");
    var1.Append("          tblpullsms.recov,tblpullsms.ID, \n");
    var1.Append("          ev.enumerationvalue \n");
    var1.Append("ORDER  BY tblpullsms.createddate DESC ");

    String strdailyreportsms = string.Empty;
    SqlCommand cmd = new SqlCommand();
    strdailyreportsms = var1.ToString();
    cmd.CommandType = CommandType.Text;
   
    cmd.CommandText = strdailyreportsms;
    DataSet ds = new DataSet();
    ds = MOLDBAccess.ExecuteDataSet(cmd);

    if (ds.Tables[0].Rows.Count > 0)
    {
        //grdupload.DataSource = ds;
        grdupload.DataSource = ds.Tables[0];
        grdupload.DataBind();


    }
    else
    {
        grdupload.DataSource = null;
        grdupload.DataBind();
    }
}

推荐答案

如果没有告诉我们错误来自哪一行,那么''很难准确,但可能你需要查看 MOLDBAccess.ExecuteDataSet 的返回值,然后在 grdupload 。它们是你在使用它们之前没有显示被声明或初始化的唯一变量,所以它们中的一个或其他将为空 - 但我不知道从哪里开始。



在调试器中运行代码,并在
Without you telling us exactly which line the error is coming from, it''s difficult to be precise, but probably you need to look at the return value from MOLDBAccess.ExecuteDataSet, then at grdupload. They are the only variables which you do not show being declared or initialised before you use them, so one or other of them will be null - but I can''t tell which from here.

Run your code in the debugger, and either put a breakpoint on the
DataSet ds = new DataSet();

行上放置一个断点并逐步执行,查看变量在每一步,或运行它直到异常发生,并查看它抱怨的变量。



然后你必须弄清楚它为什么是空的 - 但这超出了你向我们展示的代码的范围。

line and step through, looking at your variables at each step, or run it until the exception occurs and look at the variable it is complaining about.

You will then have to work out why it is null - but that is outside the scope of the code you have shown us.


这篇关于Object引用对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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