Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
| Search | Today's Posts | Mark Forums Read
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 December 29th, 2005, 07:50 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2005
Location: , , .
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your going to love me. Unfortunately this still does not work. (Although to be honest I really thought it would do). Here is the current code.

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim strPatNum As String = Request.QueryString("PatNum")
cnBarwickPas.Open()
Dim cmdPatsNextKin As New Odbc.OdbcCommand("SELECT ASSETCOM.MASTER5.MSMROL, ASSETCOM.NEXTKIN.NKMROLL, ASSETCOM.NEXTKIN.NKTITLE, ASSETCOM.NEXTKIN.NKFOREN, ASSETCOM.NEXTKIN.NKSURNM, ASSETCOM.NEXTKIN.NKADDR1, ASSETCOM.NEXTKIN.NKADDR2, ASSETCOM.NEXTKIN.NKADDR3, ASSETCOM.NEXTKIN.NKADDR4, ASSETCOM.NEXTKIN.NKPOST7, ASSETCOM.NEXTKIN.NKPHONE, ASSETCOM.NEXTKIN.NKRELAT FROM ASSETCOM.MASTER5, ASSETCOM.NEXTKIN WHERE ASSETCOM.MASTER5.MSMROL = ASSETCOM.NEXTKIN.NKMROLL AND ASSETCOM.MASTER5.MSMROL =" & strPatNum, cnBarwickPas)
Dim drPatsNextKin As Odbc.OdbcDataReader
drPatsNextKin = cmdPatsNextKin.ExecuteReader()
lblTitleSts.Text = drPatsNextKin.GetString(drPatsNextKin.GetOrdinal("NKTITLE"))
lblTitleSts.DataBind()
drPatsNextKin.Close()
cnBarwickPas.Close()

End Sub
This error I receive is:
Code:
No data exists for the row/column. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: No data exists for the row/column.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[InvalidOperationException: No data exists for the row/column.]
   System.Data.Odbc.OdbcDataReader.internalGetString(Int32 i) +425
   System.Data.Odbc.OdbcDataReader.GetString(Int32 i) +5
   DDHPAS.WebForm7.Page_Load(Object sender, EventArgs e) +170
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731
So I thought i would double check in SQL that there is data regarding that PatNum and there is, I also double checked to make sure that strPatNum was receiving the value from the query string request and it is.

As soon as I it tries to process this line "lblTitleSts.Text = drPatsNextKin.GetString(drPatsNextKin.GetOrdinal(" NKTITLE"))" thats when it falls over.

I also tried it with the "rPatsNextKin = cmdPatsNextKin.ExecuteReader(CommandBehavior.Singl eRow)" as well.
 
Old December 29th, 2005, 08:05 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

A few things you can try:

1. Write out the complete SQL statement before you execute the reader. Then paste it in the query designer of your database and see if it works.

2. Remove the WHERE clause from your SQL. Then you can see what happens when you get a result set.

3. Check for HasRows to see if the reader returned a row before you try to access its data.

BTW, there is no need to call DataBind() on the label. Setting its Text property directly is enough.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 29th, 2005, 08:07 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Oh, and make sure you use the check for DBNull.Value I showed you earlier. Maybe there is a record, but the column you're trying to access is empty (null).

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old January 16th, 2006, 05:37 PM
Registered User
 
Join Date: Jan 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

I have the similiar problem.
I'm using datareader (let's call it dr) to retrieve data from MS-SQL
and also receive an "No data exists for the row/column" error
when using dr.IsDBNull(0) method???

1. I've checked that datareader object contains data (dr.HasRows is true)
2. Other methods like dr.GetString(0) or dr.GetDataType(0) works fine!!!
3. But... using dr.IsDBNull(0) raises an error!!!

What may be the reason?
This issue is CRITICAL for me.

HELP please,
Helena




Similar Threads
Thread Thread Starter Forum Replies Last Post
Rows 2 Columns kilika Oracle 0 October 14th, 2005 01:16 PM
Columns To Rows alyeng2000 SQL Language 2 March 11th, 2005 03:08 PM
Data Report: Columns Against Rows bemular VB How-To 0 January 6th, 2005 12:52 AM
Rows into columns shamsad Oracle 0 April 7th, 2004 04:38 AM





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