Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2004, 07:41 AM
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in SQL query

I have this Code

CommandText = "SELECT firstName FROM Students Where Students.ID
='"&idNum& "'"

myCommand = New SqlCommand(CommandText, myConnection)
Dim name As String = myCommand.ExecuteReader.GetString(0)
Response.Write(name)
myConnection.Close()



I get this Error massage:

Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present.






 
Old November 8th, 2004, 12:37 AM
Friend of Wrox
 
Join Date: Feb 2004
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Check whether record exists before you start reading it.
i.e. before assigning the value check if it exists.

It is not how much we do,
but how much love we put in the doing.

-Mother Theresa





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query Problem mike.chary SQL Server 2005 1 September 26th, 2007 06:19 AM
SQL Query problem skarthikk SQL Server 2000 1 August 7th, 2006 02:20 AM
SQL query problem - Need Help Settt Biztalk 0 September 12th, 2005 09:32 AM
sql query problem Baby_programmer ASP.NET 1.0 and 1.1 Basics 1 October 14th, 2004 07:13 AM
Sql Query Problem mateenmohd SQL Language 0 January 13th, 2004 05:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.