SqlDataReader dr1.Read() coming false

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Parul Vinod
    New Member
    • Aug 2011
    • 36

    SqlDataReader dr1.Read() coming false

    I am using Visual Studio 2008; I am executing one query and its results are coming in the datareader dr1; I have checked this in debug window. Even though values are coming inside datareader it's read property dr1.read() is coming false. How is this happening. How do i remove this bug
  • Parul Vinod
    New Member
    • Aug 2011
    • 36

    #2
    The resulting values of query comes in dr1. in debugger under the haeding
    Result View-> [0]-> Non-public members-> _values. And still dr1.read() is coming false.People plz reply. This is urgent.

    Comment

    • PsychoCoder
      Recognized Expert Contributor
      • Jul 2010
      • 465

      #3
      Show the code you're using for this task and we will have a better idea on why this is happening.

      Comment

      • Parul Vinod
        New Member
        • Aug 2011
        • 36

        #4
        Code:
        query1="select username,date,subject,description from doubts where heading='" + strheading + "'"
        con.Open();
        SqlCommand cmd1= new SqlCommand(query1,con);
        SqlDataReader dr1;
        dr1=cmd1.ExecuteReader();
        I just changed the sequence of username, date into date,username and now the code is working. I still don't know the exact reason why this happened. Is it because in database i have difined date before username?

        Comment

        • sarva
          New Member
          • Jan 2012
          • 1

          #5
          date is one kind of keyword in sql. change your field name!!!!

          pls try it ....

          best regards
          Sarva

          Comment

          • PsychoCoder
            Recognized Expert Contributor
            • Jul 2010
            • 465

            #6
            For future reference if you have a column name that's a reserved word when you query it put brackets around it, like this [date]

            Comment

            • Parul Vinod
              New Member
              • Aug 2011
              • 36

              #7
              Thanks a lot Richard and SARVA.

              Comment

              • PsychoCoder
                Recognized Expert Contributor
                • Jul 2010
                • 465

                #8
                No problem, glad I could be helpful :)

                Comment

                Working...