Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

VB.NET app top 1 select statement wont work but does in MSSM

Hi im trying to use this sql select statement in my app but when i call it the app says 'invalid attempt to read when no data is present'.

here is my statement:

        myCommand = New SqlCommand("SELECT TOP 1 prospector.ID, prospector.adviserID, prospector.cMonth, prospector.cYear " & _
        "FROM prospector ", objConnection)

if i run it without the quotes in MSSM is works perfectly and produces just 1 row. Do i need to change something when i use top 1 in my vb app?
0
drews1f
Asked:
drews1f
  • 2
  • 2
1 Solution
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
Specify the Schemaname in front of the table name like schemaname.prospector.
0
 
drews1fAuthor Commented:
i tried this:

        myCommand = New SqlCommand("SELECT TOP 1 ID, adviserID, cMonth, cYear " & _
        "FROM [myo].[dbo].[prospector] ", objConnection)

but got the same result!
0
 
jpaulinoCommented:
SqlCommand are used to INSERT, UPDATE and DELETE methods and not SELECTS. You have to use an SqlDataReader and do an ExecuteReader instead SqlCommand
0
 
jpaulinoCommented:
0
 
drews1fAuthor Commented:
Oh! Didn't know that! Works fine now!! Thanks
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now