Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8
This is the forum to discuss the Wrox book Visual Basic 2008 Programmer's Reference by Rod Stephens; ISBN: 9780470182628
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Visual Basic 2008 Programmer's Reference ISBN: 978-0-470-18262-8 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
  #1 (permalink)  
Old August 7th, 2011, 06:38 PM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Column name 'id' is defined for different mapping types

I keep getting this exception in one particular instance of reading an XML stream. Search engine on this topic returns a lot of questions, but no real solution. I do understand why I get that message, but I cannot figure out a way to avoid it.

The XML data looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<response query="Payments" id="19068">
<results amount="7621" offset="0"/>
<userPayment id="0">
<Id>20650806</Id>
(...)

so I'm guessing the problem is that there's multiple different "types" of "Id"... I have no control over the data, so I cannot change anything to it.

VB Code is like this:

(...)
'Load data into Dataset
dsUserLog = New Dataset
dsUserLog.ReadXml (response.GetResponseStream)
(...)

This last line is where it raises the exception.

Any idea how I can get past that without modifying the XML?

thanks!!
  #2 (permalink)  
Old August 7th, 2011, 09:49 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

I'm really not sure. If the data is regular enough, perhaps you could use an xsd to define the structure enough to handle it.

But it's been a while since I've look at this sort of problem. You might be better off posting to an active XML forum, if you can find something like that.

I'm also not sure why it would care that there is an id property and an id item. I would have thought it would be smart enough to differentiate the two.

Sorry I can't be more help.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #3 (permalink)  
Old August 8th, 2011, 10:14 AM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rod,

I'm not sure I really understand why, but it is working, thanks to your suggestion. I had to google quite a bit to find out how to put the pieces together, but I'm happy it's now working. Here's what I did:

1) Saved the xml data into a text file (userlog.xml)
2) Used xsd to extract the info (xsd userlog.xml /d /l:VB)

Then, I read the schema followed by the xml, and it just works without any other changes. My only problem is understanding how to used the xsd when it's added to the project. I couldn't figure out how to reference it, so I'm reading it from file on disk with

dsUsedLog.ReadXMLSchema("path\to\userlog.xsd")

which works fine, as long as I remember to copy the xsd file to the application folder once it's all done. Right now, the file sits in the Debug folder, which works fine for the time being...
  #4 (permalink)  
Old August 8th, 2011, 10:46 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Talk about lucky guesses

I think you can make the project copy the file into the executable directory if you:

- Add the xsd file to the project
- Select it in Solution Explorer
- In the Properties window, set BuildAction = Content and "Copy to Output Directory" = "Copy if newer"

Hopefully then you'll be able to load it from the directory where the exe file is.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #5 (permalink)  
Old August 8th, 2011, 11:40 AM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yep! that did it! thanks Rod!!
  #6 (permalink)  
Old August 9th, 2011, 12:40 PM
Registered User
 
Join Date: Sep 2009
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As an added note, I should clarify that it wasn't as simple as noted above, although that's what put me on the right track. XSD.EXE created a huge schema file, which in turn generated hundreds of warnings in my project. I ended up looking for a different tool, came across XMLPad which generated a much smaller file. Yet, although it wouldn't crash anymore, I kept getting no data for the right table, or a blank datagridview. Turns out that in order to avoid the confusion between 'Id' and 'id', I enabled case sensitivity on my dataset, but used the wrong capitalization on the table name I was trying to load. Small details... :)
  #7 (permalink)  
Old August 9th, 2011, 12:59 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Thanks for posting the followup. If others have similar problems, it will come in handy!
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #8 (permalink)  
Old June 7th, 2012, 05:09 AM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Try to remove attributes

... may be this helps ...

Code:
System.Xml.XmlNode xmlNode = ... some code ...
xmlNode.Attributes.RemoveAll();
DataSet dataSet = new DataSet();
dataSet.ReadXml(new System.IO.StringReader(xmlNode.OuterXml));

Last edited by opochitsky; June 7th, 2012 at 05:10 AM.. Reason: mistake


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why do we add an Id column to our tables? robbaralla BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 8 December 5th, 2009 04:48 PM
Operator '&' is not defined for types 'String' sharon5469 ASP.NET 1.0 and 1.1 Basics 2 May 28th, 2007 10:02 AM
identity column id find!! keyvanjan Classic ASP Basics 7 January 20th, 2007 01:12 PM
ADO and user-defined data types rgerald SQL Server 2000 3 June 20th, 2005 11:43 AM
DTS Column Mapping Problem hortoristic SQL Server 2000 2 August 2nd, 2004 03:21 PM





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