No data exists for the row/column

My page reads data to display it in a chart using a 3rd party charting tool called FusionCharts

I can get System.InvalidOperationException: No data exists for the row/column if the table has no data on it. How can I prevent this error (it is possible that there won't be data)?  Here's the code that reads the data

cmdSelectInputs = New OleDbCommand(sql, conInputs)
' Returns one row only
dtrInputs = cmdSelectInputs.ExecuteReader(CommandBehavior.SingleRow)
' Must call read or get an error

display dtrInputs(fieldName) in a text field  'here's the line with the error
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimCotteeHead of Software ServicesCommented:
Hi rwallacej,

Check the return value from the read call:

If dtrInputs.Read() Then
    txtdtrinputs.text = dtrinputs(fieldname)
    txtdtrinputs.text = "No Data to display!"
End If

Tim Cottee
rwallacejAuthor Commented:

the values aren't actually just displayed in a text field, they're used to build up an in-memory xml file for the chart program to plot a graph

the page expires after 5 seconds using <meta http-equiv="refresh" content="5" />

if there's no data, I'd like to display the chart as it was in its previous state when there WAS data. can I do this?
something like "

1. create the virtual xml for the chart and display it,
2. after 5 secs refresh the page -
 - if data is there, display new chart
 - if there's no data there, display chart as it was at 1.

hope I'm explaining myself ok
TimCotteeHead of Software ServicesCommented:

Providing you persist the "valid" xml data across the postback in cache for example then absolutely you can.

Instead of writing to the textbox use something like:

If dtrInputs.Read() Then
End If

Then you can have your chart populated using Cache.Item("VirtualXML") as this will only be updated when there is new data retrieved from the data reader.

Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

rwallacejAuthor Commented:
maybe you can help a bit more

the chart object gets things just now like
<EMBED src="FC_2_3_MSScatter.swf" FlashVars="dataXML=<%= getFCXMLData() %>"

getFCXMLData() reads all the data and builds up the "virtual" xml file (the file isn't stored to a hard drive) and returns it as a string. the string is used by the embedded chart

do I put this string in cache or something and if returns false, return the cache value ?  sorry I'm not very competent !
TimCotteeHead of Software ServicesCommented:

Yes, exactly that. Perhaps in fact a session variable would be better than cache because cache is global in scope whereas a session variable is maintained for that user's session only.

So this data reader is used in the getFCXMLData() call I assume.

If so you need to perhaps add some extra logic:

If the data reader returns nothing then instead of returning partially formed XML data, return a fixed value "INVALID" perhaps.

Then you can use this to determine whether to store the value in the session variable or not:

Dim strXML as String = getFCXMLData()
If strXML = "INVALID" Then
 'We haven't got any new data so keep the old
 Session("XMLData") = strXML
End If

You can then use Session("XMLData") to supply the data to your chart object.

<EMBED src="FC_2_3_MSScatter.swf" FlashVars="dataXML=<%=Session("XMLData")%>"


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rwallacejAuthor Commented:

thank-you for your great help and pleasant nature...the problems solved now. by putting the virtual xml file into the session I can delete data till my hearts content knowing that there won't be any problems with System.InvalidOperationException: No data exists for the row/column, and that the chart will display the previous data

excellent - you're a model Expert!
TimCotteeHead of Software ServicesCommented:

You are more than welcome, glad I could help.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.