473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamic ctype?

I am attempting to write a 'factory' function to use in a generated data
access layer to accept a sqldbtype and convert it to the appropriate
system.type.

I have attempted to use ctype (value, typename)
where value is the sqlreader field object and typename is a variable
containing the required type as a system.type and I'm getting nowhere.

Any ideas appreciated.

Thanks in anticipation,

Mike
Jan 5 '06 #1
3 1255
Why not create a 'hard coded' list for the purposes of this type conversion.
I use Codesmith to produce my data access layer and when building the .NET
classes, I use a function (that is a standard part of one of the CodeSmith
templates) to produce compatible type definitions. The function is relatively
small and I have had no problems with it at all. If you are interested, I
could provide you with the type mappings I use.

Regards,

-Eric
"MikeG" wrote:
I am attempting to write a 'factory' function to use in a generated data
access layer to accept a sqldbtype and convert it to the appropriate
system.type.

I have attempted to use ctype (value, typename)
where value is the sqlreader field object and typename is a variable
containing the required type as a system.type and I'm getting nowhere.

Any ideas appreciated.

Thanks in anticipation,

Mike

Jan 5 '06 #2
Thanks Eric,

I was hoping to avoid a 'case' statement if possible.

Regards,

Mike

"Eric Giles" wrote:
Why not create a 'hard coded' list for the purposes of this type conversion.
I use Codesmith to produce my data access layer and when building the .NET
classes, I use a function (that is a standard part of one of the CodeSmith
templates) to produce compatible type definitions. The function is relatively
small and I have had no problems with it at all. If you are interested, I
could provide you with the type mappings I use.

Regards,

-Eric
"MikeG" wrote:
I am attempting to write a 'factory' function to use in a generated data
access layer to accept a sqldbtype and convert it to the appropriate
system.type.

I have attempted to use ctype (value, typename)
where value is the sqlreader field object and typename is a variable
containing the required type as a system.type and I'm getting nowhere.

Any ideas appreciated.

Thanks in anticipation,

Mike

Jan 5 '06 #3
But what would that function return?
You would have to declare the return type as whatever the lower common
denominator is - and that would defeat the purpose of the function. Even if
you CType it inside, if the return type is the ancestor class, then anything
calling the function thinks it is getting an ancestor class. So calling the
function was just a waste of time, really.

If this is not what you are trying to do, then I think the Case statement is
your only solution. But that shouldn't be a problem, since you presumably
want to do something with the object afterwards - but you would have to
already know what type it is during coding to be able to call anything
specific to the type anyway. So it really shouldn't be a problem.

"MikeG" <Mi***@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
I am attempting to write a 'factory' function to use in a generated data
access layer to accept a sqldbtype and convert it to the appropriate
system.type.

I have attempted to use ctype (value, typename)
where value is the sqlreader field object and typename is a variable
containing the required type as a system.type and I'm getting nowhere.

Any ideas appreciated.

Thanks in anticipation,

Mike

Jan 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
3
by: Stu | last post by:
Hi, I am creating a control in a PlaceHolder like so: Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim ctrl As...
3
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the...
4
by: Bass Pro | last post by:
Hi, I am creating textbox, radiobuttonlist and checkboxlist dynamically depending on data from a table. It is a questionnaire. I add the control on a Panel control during the 1st load_page event....
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
3
by: Andreas Wöckl | last post by:
Hi Group! I have a web form that is created dynamically - so I create Textboxes, RadioButtonLists, CheckBoxLists and so on - I have found some articles that there may be some problems with...
0
by: shahDeveloper | last post by:
i have created a number of combo boxes according to my need.no i want to save the changes when any one click update button,but here the control did not find by findcontrol function. Dim i, j, totc...
1
by: SunshineInTheRain | last post by:
The following code is dynamic create dropdownmenu which data within pulled from database However, the code work well on IE but not on Firefox. On Firefox, the whole mouseover and mouseout function...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
12
by: ive1122 | last post by:
Hi guys, I am looking into create a dynamic survey as posted in Get User Input From Dynamic Controls but with some different environment Below is what i am trying to do: First when the user...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.