Home All Groups Group Topic Archive Search About

Data Reader Problem

Author
12 Jul 2006 12:06 PM
Nalin
Hello guys,

Please, anyone already see this problem ?


[NullReferenceException: Object reference not set to an instance of an
object.]
   System.Data.SqlClient.SqlDataReader.PrepareSQLRecord(Int32 i) +159
   System.Data.SqlClient.SqlDataReader.GetSqlString(Int32 i) +20
   System.Data.SqlClient.SqlDataReader.GetString(Int32 i) +32


The properties HasRows and isClosed is okay... The reader has rows and
not closed !!


How do to solve this ?


Thanks a lot and sorry.... my english is so bad.

Author
12 Jul 2006 3:04 PM
AlBruAn
It's hard to tell what's happening to cause the exception to be thrown
without the code where the error is occurring.  Could you copy a few lines of
the code up to, and including, the line on which the error occurred?  That
would go a long way to help in determining what's causing the exception.

Regards,

Allen Andersn
Author
12 Jul 2006 4:05 PM
Nalin
The error occurs in method setNewRow at the first GetString() . The
entry point is the ExecuteRelatorio() method.


                protected void setNewRow(int loopIndex, DataTable
dtRet,Abit.Comex.Data.DataReader dr)
                {
                                DataRow newRow = dtRet.NewRow();
                                newRow[0] = dr.Reader.GetString(0);
                                dr.Reader.GetInt32(1);
                                if(dr.Reader[2] != DBNull.Value)
newRow[2] =
dr.Reader.GetString(2);
                                if(dr.Reader[3] != DBNull.Value)
newRow[loopIndex+3] =
dr.Reader.GetDouble(3);
                                if(dr.Reader[4] != DBNull.Value)
newRow[loopIndex+4] =
dr.Reader.GetDouble(4);
                                dtRet.Rows.Add(newRow);
                }


                public DataTable ExecuteRelatorio(IRelatorioExecution
DataClassExecution, TypeRelatorio TipoRelatorio,string FiltroNCMIni,
string FiltroNCMFinal, params DateTime[] Dates)
                {
                        DataTable dtRet = GetRelatorioDataTable(Dates);

                        HelperCommand HComm = null;
                        for(int i = 0; i < Dates.Length; i=i+2)
                        {
                                if(TipoRelatorio ==
TypeRelatorio.Exportacao) HComm =
DataClassExecution.ExecuteRelatorioExp(FiltroNCMIni, FiltroNCMFinal,
Dates[i],Dates[i+1]);
                                else HComm =
DataClassExecution.ExecuteRelatorioImp(FiltroNCMIni,
FiltroNCMFinal, Dates[i],Dates[i+1]);
                                DataReader dr =
HComm.ExecuteReader(CommandBehavior.CloseConnection);
                                if(dr.Reader.IsClosed) return(dtRet);
                                while (dr.Reader.Read())
                                {
                                        if(i==0) setNewRow(i,dtRet,dr);

                                        else
                                        {
                                                string NCM =
dr.Reader.GetString(0);
                                                int ID =
dr.Reader.GetInt32(1);
                                                DataRow[] rows =
dtRet.Select("ID=" + ID + " and NCM ='"+ NCM
+"'");
                                                if(rows.Length == 0)
setNewRow(i,dtRet,dr);
                                                else
                                                {
                                                        rows[0][i+3] =
dr.Reader.GetDouble(3);
                                                        rows[0][i+4] =
dr.Reader.GetDouble(4);
                                                }
                                        }


                                }
                                dr.Reader.Close();
                                HComm.CommandDisponse();
                        }
                        HComm.Finish();
                        return(dtRet);
                }




AlBruAn (donotspam) wrote:
Show quote
> It's hard to tell what's happening to cause the exception to be thrown
> without the code where the error is occurring.  Could you copy a few lines of
> the code up to, and including, the line on which the error occurred?  That
> would go a long way to help in determining what's causing the exception.
>
> Regards,
>
> Allen Andersn

AddThis Social Bookmark Button