dynamic deserialization
-
i have a table with th schema productid int productname varchar productattribute xml where the productattribute is supply by user through form say (12seagate) how can i deserialize this on the fly so i can say product.productattribute.size =12
Ebube wrote:
how can i deserialize this on the fly so i can say product.productattribute.size =12
This doesn't make sense to me. Are you asking how you can set the value of a property that doesn't exist at design time?? You can't, since, obviously, the
size
property doesn't exist. It must be defined in the class before you can use it. You can do something more like this:product.productattribute("size") = 12
IF this is what you're really trying to do...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Ebube wrote:
how can i deserialize this on the fly so i can say product.productattribute.size =12
This doesn't make sense to me. Are you asking how you can set the value of a property that doesn't exist at design time?? You can't, since, obviously, the
size
property doesn't exist. It must be defined in the class before you can use it. You can do something more like this:product.productattribute("size") = 12
IF this is what you're really trying to do...
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...thanks Dave Kreskowiak actually am looking for a way to break up this attribute so that i can have a report that look like ram size 256 maker seagate price 50 note that this value exit in database but size and maker are nodes in the (xml productattribute column)
-
thanks Dave Kreskowiak actually am looking for a way to break up this attribute so that i can have a report that look like ram size 256 maker seagate price 50 note that this value exit in database but size and maker are nodes in the (xml productattribute column)
You're going to have to explain this from the start. What you're saying doesn't make any sense at all. Report?? What report?? Where is the data stored and how? What's with the syntx you want?? how do the two relate to each other??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
thanks Dave Kreskowiak actually am looking for a way to break up this attribute so that i can have a report that look like ram size 256 maker seagate price 50 note that this value exit in database but size and maker are nodes in the (xml productattribute column)
Your question still isn't very clear. Are you saying that productattribute is stored as XML, so for example:
<productattribute>
<maker>Seagate</maker>
<size>256</size>
<price>50</price>
</productattribute>and you want to know how to break that XML up to get the sub-nodes for reporting. Is that the question?
-
Your question still isn't very clear. Are you saying that productattribute is stored as XML, so for example:
<productattribute>
<maker>Seagate</maker>
<size>256</size>
<price>50</price>
</productattribute>and you want to know how to break that XML up to get the sub-nodes for reporting. Is that the question?
-
This may be of help to you: XML data type tips in SQL Server 2005[^] It contains an example of how to work with XML data types in VB.
-
This may be of help to you: XML data type tips in SQL Server 2005[^] It contains an example of how to work with XML data types in VB.
thanks a lot. i hv read it he say "Let's say our Products table might have ProductID, ProductName, ProductCategory and ProductAttributesXML. We would then use ProductCategory to decide what type of class we store in ProductAttributesXML. So for ProductCategory='Digital Cameras" we could define a class DigitalCameraAttributes with fields such as Pixels, MaximumZoom, StorageType, and a special user control to show these details. Likewise, a class called HardDiskAttributes for the Hard Disks category." now i want to allow user to specifies this fields from form. so how can i define the class base on their input thanks
-
You're going to have to explain this from the start. What you're saying doesn't make any sense at all. Report?? What report?? Where is the data stored and how? What's with the syntx you want?? how do the two relate to each other??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...thanks a lot dave. i hv read it he say "Let's say our Products table might have ProductID, ProductName, ProductCategory and ProductAttributesXML. We would then use ProductCategory to decide what type of class we store in ProductAttributesXML. So for ProductCategory='Digital Cameras" we could define a class DigitalCameraAttributes with fields such as Pixels, MaximumZoom, StorageType, and a special user control to show these details. Likewise, a class called HardDiskAttributes for the Hard Disks category." now i want to allow user to specifies this fields from form cos i do not know at design time the product fields. so how can i define the class base on their input. i hope it make sense.
-
thanks a lot dave. i hv read it he say "Let's say our Products table might have ProductID, ProductName, ProductCategory and ProductAttributesXML. We would then use ProductCategory to decide what type of class we store in ProductAttributesXML. So for ProductCategory='Digital Cameras" we could define a class DigitalCameraAttributes with fields such as Pixels, MaximumZoom, StorageType, and a special user control to show these details. Likewise, a class called HardDiskAttributes for the Hard Disks category." now i want to allow user to specifies this fields from form cos i do not know at design time the product fields. so how can i define the class base on their input. i hope it make sense.
Yikes. The only way this would be possible is if you generated code, compiled it and emitted an assembly for it at runtime. This is a VERY ADVANCED level topic and not something I've done, so I don't have any examples. For something like this, normally I'd use something like a "property bag" setup, where basic definitions for various fields common to all class types are defined in a custom collection. That collection would also use a seperately defined "property bag" kind of setup where you're storing key/value type/value information in a seperate collection. You'd also need custom serializer/deserializers to store/parse the data in/from XML files. If you really want the custom generated class route, Google for ".net dynamic class creation".
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Yikes. The only way this would be possible is if you generated code, compiled it and emitted an assembly for it at runtime. This is a VERY ADVANCED level topic and not something I've done, so I don't have any examples. For something like this, normally I'd use something like a "property bag" setup, where basic definitions for various fields common to all class types are defined in a custom collection. That collection would also use a seperately defined "property bag" kind of setup where you're storing key/value type/value information in a seperate collection. You'd also need custom serializer/deserializers to store/parse the data in/from XML files. If you really want the custom generated class route, Google for ".net dynamic class creation".
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...thanks Dave am already storing key/value type/value information in the xml column in the database. i dont no much about custom serializer/deserializers. but the fact is that i only need to break this during report. i dont know if crytal report hav this ability to pull key/value type/value information from sql server