Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Data Reader Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nalin - 12 Jul 2006 13:06 GMT
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.
AlBruAn - 12 Jul 2006 16:04 GMT
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
Nalin - 12 Jul 2006 17:05 GMT
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);
               }

> 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
[quoted text clipped - 4 lines]
>
> Allen Andersn

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.