Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-19
5
Medium Priority
?
541 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

971 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