Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 545
  • 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
 
Jorge PaulinoIT Pro/DeveloperCommented:
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
 
Jorge PaulinoIT Pro/DeveloperCommented:
0
 
drews1fAuthor Commented:
Oh! Didn't know that! Works fine now!! Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

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