Click here to Skip to main content
15,748,330 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi all
i have small query like 'select top 1 from itemmaster where itemcode='XXXXX'
this above query returning 1 row from itemaster table

but when i call this same query from using sqldatareader its return 0 row, i couldn't find the solution pls give me some idea exparts

this is my code
dim qry as string = 'select top 1 from itemmaster where itemcode=XXXXX' 
dim openrs1 as sqldatareader
Dim cmd As New SqlCommand(qry, myConnectionstring)
       cmd.Connection = con1
       OpenRs1 = cmd.ExecuteReader()
Updated 24-Jun-12 4:05am
OriginalGriff 24-Jun-12 9:57am    
Show the code!
Use the "Improve question" widget to edit your question and provide better information.

1 solution

Even after updating question with code snippet, it looks incomplete and does not makes much sense on what you say.

Look here on how to use DataReader to fetch data from database:
Using connection
        Dim command As SqlCommand = New SqlCommand( _
          "SELECT CategoryID, CategoryName FROM Categories;", _

        Dim reader As SqlDataReader = command.ExecuteReader()

        If reader.HasRows Then
            Do While reader.Read()
                Console.WriteLine(reader.GetInt32(0) _
                  & vbTab & reader.GetString(1))
            Console.WriteLine("No rows found.")
        End If

    End Using

Retrieving Data Using a DataReader (ADO.NET)[^]
DataReader Class[^]
Share this answer
Pandvi 24-Jun-12 21:43pm    
Good Job!
Sandeep Mewara 25-Jun-12 13:22pm    
Sergey Alexandrovich Kryukov 24-Jun-12 21:54pm    
Right, a 5.
Sandeep Mewara 25-Jun-12 13:23pm    
Thanks SA.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900