Solved

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

Posted on 2009-05-19
5
532 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now