Click here to Skip to main content
16,018,904 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 vb.net using sqldatareader its return 0 row, i couldn't find the solution pls give me some idea exparts

this is my code
VB
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()
Posted
Updated 24-Jun-12 4:05am
v2
Comments
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:
VB
Using connection
        Dim command As SqlCommand = New SqlCommand( _
          "SELECT CategoryID, CategoryName FROM Categories;", _
          connection)
        connection.Open()

        Dim reader As SqlDataReader = command.ExecuteReader()

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

        reader.Close()
    End Using

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