-
LINQ Query with a Null Reference Exception
Code:
Dim strAuthorSearch As String
strAuthorSearch = "http://isbndb.com/api/authors.xml?access_key=CYGCL3GT&index1=name&value1=" & Me.txtSearchTerm.Text
Clipboard.SetText(strAuthorSearch)
xResults = XElement.Load(strAuthorSearch)
Dim authors = From retwriter In xResults.Descendants("AuthorData") Select AuthorID = xResults.Attribute("person_id").Value, Name = Me.txtSearchTerm.Text
For Each retwriter In authors
strSearchKey = retwriter.AuthorID
Next
strURLSearch = strURLSearch & "person_id"
xResults = Nothing
And on a Search of Mark Twain here's what I get back.
Code:
<ISBNdb server_time="2008-12-28T02:16:11Z">
−
<AuthorList total_results="5" page_size="10" page_number="1" shown_results="5">
−
<AuthorData person_id="mark_twain_the_author">
<Name>Mark Twain The Author</Name>
</AuthorData>
−
<AuthorData person_id="twain_mark_a01">
<Name>TWAIN MARK</Name>
</AuthorData>
−
<AuthorData person_id="mark_twain_media">
<Name>Mark Twain Media</Name>
</AuthorData>
−
<AuthorData person_id="bancroft_library_mark_twain_pr">
<Name>Bancroft Library Mark Twain Project</Name>
</AuthorData>
−
<AuthorData person_id="twain_mark">
<Name>Twain, Mark</Name>
</AuthorData>
</AuthorList>
</ISBNdb>
But I'm getting a NullReferenceError
Last edited by Hack; 12-30-2008 at 09:17 AM.
Reason: Added Code Tags
-
Do you have blank, or empty records, that it could be hitting?
-
Don't think so. Just to be on the safe side I did a Clipboard.SetText with the URL and then brought it up in Firefox. It seemed to be accurate. I was just wondering if I was misspelling something.
-
 Originally Posted by pueblonative
I did a Clipboard.SetText with the URL and then brought it up in Firefox. It seemed to be accurate.
So are you having the problem based on the browser you are using (I hate those!)?
-
Don't think so either. The XML I posted up is what I'm getting from the isbndb.com in both Firefox AND directly through my VB app.
-
Ok.
However, if you are getting a Null exception, that means something is coming back as Null.
You are doing a search on Author Names. That would indicate there is an author name that is Null or one or more of the person_Id pieces of information is Null.
Does this error occur regardless of the author you are doing the search for or only when you do Mark Twain?
-
Regardless. I even just to be on the safe side did a find and replace on all the spaces in the search term. No go.
-
Lets look at this.
http://isbndb.com/api/authors.xml?access_key=CYGCL3GT&index1=name&value1=" & Me.txtSearchTerm.Text
If you hard code values for "name", "value1" and "txtSearchTerm.Text", do you have any problems running it?
-
-
 Originally Posted by pueblonative
Yep, same problem.
BTW, here's the documentation on the XML for that site. Maybe it helps.
http://isbndb.com/docs/api/54-authors.html
-
The problem is in the line:
Code:
Select AuthorID = xResults.Attribute("person_id").Value
The xResults variable refers to the root of the document, which doesn't have a "person_id" attribute. Try changing the code to:
Code:
Select AuthorID = retwriter.Attribute("person_id").Value
-
Thank you, thank you, thank you! That did the trick.
Similar Threads
-
By pieneman in forum Database
Replies: 7
Last Post: 08-15-2008, 01:09 PM
-
Replies: 1
Last Post: 07-20-2006, 12:46 AM
-
By Colin McGuigan in forum Database
Replies: 12
Last Post: 04-15-2002, 07:43 AM
-
By Mohan Ekambaram in forum Database
Replies: 0
Last Post: 12-09-2001, 12:56 PM
-
Replies: 1
Last Post: 06-04-2001, 02:10 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|