GetTableFromDataReader loosing data type

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
6/7/2011 5:12:19 AM
Gravatar
Total Posts 87

GetTableFromDataReader loosing data type

Hi

not sure if it is a bug or there was some idea but why in GetTableFromDataReader method you are missing 

row like this 

column.DataType = Type.GetType(schemaTable.Rows[i]["DataType"].ToString());

i tryed to bind some data to gridview and all types become string types and i can't use format string feature of gridview, so far i've made a copy of this method to make a quick fix for myself but it would be greate to make this in mojosource or may be make additional method with typing if you need this one without data types transfered.

Regards,

Victor

6/7/2011 6:13:52 AM
Gravatar
Total Posts 18439

Re: GetTableFromDataReader loosing data type

Hi Victor,

If you need that I recommend copy the code and make your own custom method.

This method is not used in many places in mojoPortal and is only in places where we don't need strong typing on the DataTable, like for example if we are going to export to CSV, we have a method to export a DataTable to CSV, in which case we don't care about the data types since they all go to text.

DataTypes from the database don't exactly match .NET data types that would be needed for the DataTable columns, so to really do it right you would need to map from sql types to .NET data types.

Also since we support multiple database platforms and data types are different across database platforms and support for detecting the data types from the datareader can also vary by platform. So this method is not intended as a general purpose solution. It is difficult to make this method reliable for all database platforms, though in your custom copy of this method if you are only concerned about one database platform you can do as you wish.

Best,

Joe

6/7/2011 6:35:48 AM
Gravatar
Total Posts 87

Re: GetTableFromDataReader loosing data type

Thank you, now i see what you mean, the reason why i started to use this method is because signature of GetTable method looks like it only accepts datatable name. But after inspecting it's source code now i suspect that in tableName or whereClause i can write inner join operators to get datable based on complex join but not just simple table name. 

So is it safe and you can recommend to use GetTable to fetch joins but not single table?

Regards,

Victor

6/7/2011 6:52:19 AM
Gravatar
Total Posts 18439

Re: GetTableFromDataReader loosing data type

It may work ok, but I didn't build that method as a general purpose data access method and I don't really recommend using it as such.

That method was implemented to support some utility need that was used as part of the upgrade process for particular old versions of mojoPortal. It was mainly needed for other databases platforms (Not SQL Server), but I had to implement it in all layers in order to be able to call it from the business layer when using other databases. For example, some of the other dbs don't have a uniqueidentifer data type, so we store guids as char in those platforms and when I added a column to an existing table and I need to be able to populate the existing rows with a guid, I needed to loop through the table and update the field using a guid generated from .NET code. Whereas with sql server I could just use the newid() sql function.

So for other databases I had to implement a post upgrade procedure for some version upgrades and this method was only intended for that.

I would not use that method for data access in any feature code.

Best,

Joe

You must sign in to post in the forums. This thread is closed to new posts.