Click here to Skip to main content
15,937,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when you are reading data from a DataTable.Rows[], and loading it into a control, you can do it without converting the datatype if the target datatype matches the Db datatype. the dt.Rows[0][0].Value returns an object data type, which is
the most general datatype. if the database column is decimal and the control you are loading it to is also decimal, it will automatically cast the object datatype to a decimal without having to use Convert.ToDecimal or anyting like that. it applies to all datatypes.
It is possible in C# if yes then how to do this.
Posted

I think one of the first examples of this excellent article answers your question:
Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET[^]

So yes it's possible in c# - no explicit casting required.

Best regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 7-Jul-11 19:14pm    
Thank you, I'll take a look.
--SA
Espen Harlinn 7-Jul-11 19:49pm    
Thanks Sergey :)
VB.NET does automatic casting. C# does not. Those controls would use reflection to try to work out what the data type is, based on having been told what to expect. You can write a lot of reflection code, but it rarely makes sense. You can find out if something is a specific type using TryParse as in bool.TryParse and int.TryParse, there's no one step "return the typed object" method, as each method has only one return type.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900