locked
gives error when binding to dataset RRS feed

  • Question

  • Hello

    here is my code

     DataSet  Dst = new DataSet();;
            Dst = null;
            DataTable table;
            try
            {
                using (NewIntraWFEntities nwef = new NewIntraWFEntities())
                {
                    // takes transaction of past 1 month from today's date
    
                    var pastDate = DateTime.Today.AddDays(-30);
                    
    
                    IQueryable<MainInbox> getData = nwef.MainInboxes.Where(fil => fil.EmpIdFor == empid && fil.CreationDate > pastDate).OrderByDescending(o => o.id);
                    if (getData.Count() > 0)
                    {
                        var reader = getData.GetEnumerator();
    
                        table = new DataTable();
                        table.Columns.Add("MainText",typeof(string));
                        table.Columns.Add("CreationDate", typeof(string));
                        table.Columns.Add("ServiceName", typeof(string));
                        table.Columns.Add("fulllLink", typeof(string));
                        table.Columns.Add("EmpIdFor", typeof(string));
    
    
                        
                        while (reader.MoveNext())
                        {
                            var record = reader.Current;
                            table.Rows.Add(record.MainText, record.CreationDate, record.ServiceName, record.fulllLink, record.EmpIdFor);
                            //table.Rows.Add(record.MainText);
                        }
                        Dst.Tables.Add(table);
                        
                    }
                }
            }
            catch { }
            return Dst;

    gives error on bold line and error is  "Object reference not set to an instance of an object."

    Wednesday, March 6, 2013 8:58 AM

Answers

  • it is working now,

    you should not assign DST as null before

    • Marked as answer by alman asif Wednesday, March 13, 2013 7:03 AM
    Wednesday, March 13, 2013 7:03 AM

All replies

  • Hi,

    Are you sure it happens here ? It means that you are trying to use an object that is still uninitialized (null) but Dst and table seems ok.

    As a side note an empty catch clause is likely a bad idea (you would just ignore the error at runtime which is likely counter productive).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Wednesday, March 6, 2013 9:15 AM
  • it is working now,

    you should not assign DST as null before

    • Marked as answer by alman asif Wednesday, March 13, 2013 7:03 AM
    Wednesday, March 13, 2013 7:03 AM