364,088 Members | 5440 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

SqlDataReader dr1.Read() coming false

Parul Vinod
P: 33
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
Jan 27 '12 #1
Share this Question
Share on Google+
7 Replies


Parul Vinod
P: 33
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.
Jan 27 '12 #2

PsychoCoder
Expert Mod 100+
P: 208
Show the code you're using for this task and we will have a better idea on why this is happening.
Jan 27 '12 #3

Parul Vinod
P: 33
Expand|Select|Wrap|Line Numbers
  1. query1="select username,date,subject,description from doubts where heading='" + strheading + "'"
  2. con.Open();
  3. SqlCommand cmd1= new SqlCommand(query1,con);
  4. SqlDataReader dr1;
  5. 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?
Jan 28 '12 #4

sarva
P: 1
date is one kind of keyword in sql. change your field name!!!!

pls try it ....

best regards
Sarva
Jan 28 '12 #5

PsychoCoder
Expert Mod 100+
P: 208
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]
Jan 29 '12 #6

Parul Vinod
P: 33
Thanks a lot Richard and SARVA.
Jan 30 '12 #7

PsychoCoder
Expert Mod 100+
P: 208
No problem, glad I could be helpful :)
Jan 31 '12 #8

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework