Solved

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

Posted on 2009-05-19
5
537 Views
Last Modified: 2012-05-07
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
Comment
Question by:drews1f
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24422884
Specify the Schemaname in front of the table name like schemaname.prospector.
0
 

Author Comment

by:drews1f
ID: 24423285
i tried this:

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

but got the same result!
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24426204
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
 
LVL 48

Expert Comment

by:jpaulino
ID: 24426216
0
 

Author Comment

by:drews1f
ID: 24427633
Oh! Didn't know that! Works fine now!! Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
semaphore timeout period has expired 1 33
Use SSRS to email customers? 4 30
I need to clear List Box in MVVM panel. 15 27
T-SQL: Number of Records is Greater Than One 7 51
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question