Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > TypeConverters Usage
 

TypeConverters Usage

I have two objects (named Prod1 and Prod2)representing two tables in a sql database - the two tables are almost identical (one has constraints and the other has no constraints - it is used as a temporary table) . Considering that they are identical in properties etc..

I am wondering how I can convert Prod1 as Prod2 and vice versa - for example I grab the info from Prod1, manipulate the data using info from another source and then I wish to cast prod1 as prod2 - and save prod2 to the sql database. I know how to do everything except convert my objects ( can I simply use DirectCast(Prod1, Prod2Type) and expect it to work - or is there some rocket science I need to know ?

These were generated objects from the table names .. therefore the class names and thestored procedure names are really the difference between the two objects - along with the constraints.

I do not want to save the "original" object [Prod1] back to the "live table [Prod1]" - I want this in a temp table [prod2] so that the operator has a chance to look over the data to review, verify or fix it before committing the data - and I want them to have all the time in the world to do it - hence the temp table.

Stixoffire  Sunday, July 12, 2009 9:04 PM

Casting is when you convert object of one type into another. For example object to textbox.

Here in your case, both are objects hence you cannot type cast any of them with other.

You simply need to copy table data from Prod1 to Prod2.



Thanks

I AM OPTIMUS PRIME
Omie  Monday, July 13, 2009 6:54 AM

Casting is when you convert object of one type into another. For example object to textbox.

Here in your case, both are objects hence you cannot type cast any of them with other.

You simply need to copy table data from Prod1 to Prod2.



Thanks

I AM OPTIMUS PRIME
Omie  Monday, July 13, 2009 6:54 AM
That seems like a CPU intensive process - when we are talking about 10,000 rows (I know that is small in comparison to others I have seen).

So what about the methods CanConvertTo and CanConvertFrom - are they used for Object to Object Conversions ? If so how would that be done.

I am using a Doodads Object Generated from MyGeneration the underlying mechanism is a dataview.


I am looking into the object to see what parameters I would need to change - because just as you stated that is what I want to do is take the data I have manipulated and put it into Prod2.
Stixoffire  Wednesday, July 15, 2009 12:10 AM

Why don't you define an interface with all the properties and implement it in both classes. Than you don't have to cast/copy anything.

--
Wolfgang

Wollinet  Wednesday, July 15, 2009 5:52 AM
I do not understand how an Interface will copy the data pulled in to the object [OBJECT A] to [OBJECT B]

I know the interface will give me access to an object but how does that work for two objects that are somewhat Identical - are you familiar with the MyGeneration Doodads Architecture Object as it represents a Data Table (using a dataview as the underlying mechanism which is not directly accessible as a property object of the Object). Could you show me a simple example - ?
Stixoffire  Wednesday, September 02, 2009 3:23 AM

...can I simply use DirectCast(Prod1, Prod2Type) and expect it to work - ...... I do not want to save the "original" object [Prod1] back to the "live table [Prod1]" - I want this in a temp table [prod2] ...


I'm not familiar with MyGeneration Doodads Architecture Object, but I just had a brief view at the doc. They generate a abstract class _Prod1 and _Prod2 for you, right ? So it seems, you can't use an interface here, but can you get them to use the same abstract class for both tables ? In that case you should be able to exchange the objects without copying.

--
Wolfgang
Wollinet  Wednesday, September 02, 2009 6:04 AM

You can use google to search for other answers

Custom Search

More Threads

• BindingList bound to a list box. ResetItem calling SelectedIndexChanged
• Implementing IBindingListView.Filter
• have a problem while AutoResize the DataGridView Columns and Rows on Beta 2
• Concurrency error on Update should not be possible here
• Difference between datagrid in Windows form and ASP.net
• Empty Dataset
• Trapping keys entered in dataGridView
• Datagridview Column Sorting
• Programmatically setting the selectedindex of a ComboBox doesn't fire SelectedIndexChanged event
• Referencing tablecell text in an embedded datagrid within a datagrid