473,385 Members | 1,492 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.

Typecasting without knowing the cast

Hi

I have a data row variable which could be for any of a number of tables in
my apps. How can I type cast the variable to correct type at runtime? I know
I can get the type description using MyRow.ToString but don't know how to
use this to typecast MyRow variable. I need this to write a generic SUB that
can deal with rows of any table type.

Thanks

Regards
Jun 27 '08 #1
11 1073
"John" <in**@nospam.infovis.co.ukschrieb
Hi

I have a data row variable which could be for any of a number of
tables in my apps. How can I type cast the variable to correct type
at runtime? I know I can get the type description using
MyRow.ToString but don't know how to use this to typecast MyRow
variable. I need this to write a generic SUB that can deal with rows
of any table type.
Maybe you are looking for this:

if typeof row is CustomerRow then
directcast(row, CustomerRow).Member 'any type specific member
elseif typeof row is contractRow then

'...

end if

Type casting without knowing the destination type at design time does
not make sense. Casting is there to be able to write code that is
specific to a certain type. If you don't know the destination type, you
can not write type specific code.
Armin

Jun 27 '08 #2
On Apr 28, 10:31 pm, "John" <i...@nospam.infovis.co.ukwrote:
Hi

I have a data row variable which could be for any of a number of tables in
my apps. How can I type cast the variable to correct type at runtime? I know
I can get the type description using MyRow.ToString but don't know how to
use this to typecast MyRow variable. I need this to write a generic SUB that
can deal with rows of any table type.

Thanks

Regards
John,
To know the type of object, use GetType function to determine. Then
maybe you'll have a change for type casting.

Hope this helps,

Onur
Jun 27 '08 #3
On 2008-04-28, John <in**@nospam.infovis.co.ukwrote:
Hi

I have a data row variable which could be for any of a number of tables in
my apps. How can I type cast the variable to correct type at runtime? I know
I can get the type description using MyRow.ToString but don't know how to
use this to typecast MyRow variable. I need this to write a generic SUB that
can deal with rows of any table type.

Thanks

Regards

Assuming that Row inherits from DataRow, then that is the type you would
be working with.

--
Tom Shelton
Jun 27 '08 #4
I am trying

CType(MyRow, GetType(MyRow))

but it says 'Error 1 Keyword does not name a type' on GetType.

Thanks

Regards
"kimiraikkonen" <ki*************@gmail.comwrote in message
news:0b**********************************@a70g2000 hsh.googlegroups.com...
On Apr 28, 10:31 pm, "John" <i...@nospam.infovis.co.ukwrote:
>Hi

I have a data row variable which could be for any of a number of tables
in
my apps. How can I type cast the variable to correct type at runtime? I
know
I can get the type description using MyRow.ToString but don't know how to
use this to typecast MyRow variable. I need this to write a generic SUB
that
can deal with rows of any table type.

Thanks

Regards

John,
To know the type of object, use GetType function to determine. Then
maybe you'll have a change for type casting.

Hope this helps,

Onur

Jun 27 '08 #5
"John" <in**@nospam.infovis.co.ukschrieb
I am trying

CType(MyRow, GetType(MyRow))

but it says 'Error 1 Keyword does not name a type' on GetType.
Have you read my message? Why do you want to cast at all?
Armin
Jun 27 '08 #6
I am writing a library of generalised SUB to handle any table's row that the
user using the library may need to pass to library. I do not know the actual
type of the data row that user will be passing therefore I need to figure it
at runtime.

Thanks

Regards

"Armin Zingler" <az*******@freenet.dewrote in message
news:Oh**************@TK2MSFTNGP03.phx.gbl...
"John" <in**@nospam.infovis.co.ukschrieb
>I am trying

CType(MyRow, GetType(MyRow))

but it says 'Error 1 Keyword does not name a type' on GetType.

Have you read my message? Why do you want to cast at all?
Armin

Jun 27 '08 #7
"John" <in**@nospam.infovis.co.ukschrieb
I am writing a library of generalised SUB to handle any table's row
that the user using the library may need to pass to library. I do
not know the actual type of the data row that user will be passing
therefore I need to figure it at runtime.
Sry, I don't get it. If you don't know the actual type, how do you want
to handle different types differently? That's a contradiction.

If you determine the type at _runtime_, how do you want to take the type
into account at _design time_? Design time is before runtime.
Armin

Jun 27 '08 #8
On 2008-04-28, John <in**@nospam.infovis.co.ukwrote:
I am writing a library of generalised SUB to handle any table's row that the
user using the library may need to pass to library. I do not know the actual
type of the data row that user will be passing therefore I need to figure it
at runtime.

Thanks
John,

What kind of actions are you trying to take on these rows? Basically,
what I'm saying, is unless you know the type or the types that can be
passed, then you can't get there from here....

Like I said, you can handle all the Rows as DataRow, and that is about
as close as your going to get.

--
Tom Shelton
Jun 27 '08 #9
Thanks. I know what you mean.

Regards

"Armin Zingler" <az*******@freenet.dewrote in message
news:OD**************@TK2MSFTNGP04.phx.gbl...
"John" <in**@nospam.infovis.co.ukschrieb
>I am writing a library of generalised SUB to handle any table's row
that the user using the library may need to pass to library. I do
not know the actual type of the data row that user will be passing
therefore I need to figure it at runtime.

Sry, I don't get it. If you don't know the actual type, how do you want
to handle different types differently? That's a contradiction.

If you determine the type at _runtime_, how do you want to take the type
into account at _design time_? Design time is before runtime.
Armin

Jun 27 '08 #10
Got it. Thanks

Regards

"Tom Shelton" <to*********@YOUKNOWTHEDRILLcomcast.netwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
On 2008-04-28, John <in**@nospam.infovis.co.ukwrote:
>I am writing a library of generalised SUB to handle any table's row that
the
user using the library may need to pass to library. I do not know the
actual
type of the data row that user will be passing therefore I need to figure
it
at runtime.

Thanks

John,

What kind of actions are you trying to take on these rows? Basically,
what I'm saying, is unless you know the type or the types that can be
passed, then you can't get there from here....

Like I said, you can handle all the Rows as DataRow, and that is about
as close as your going to get.

--
Tom Shelton

Jun 27 '08 #11
http://msdn2.microsoft.com/en-us/lib...ma(vs.71).aspx

http://msdn2.microsoft.com/en-us/lib...pe(VS.71).aspx

Cor
"John" <in**@nospam.infovis.co.ukschreef in bericht
news:OF**************@TK2MSFTNGP05.phx.gbl...
Hi

I have a data row variable which could be for any of a number of tables in
my apps. How can I type cast the variable to correct type at runtime? I
know I can get the type description using MyRow.ToString but don't know
how to use this to typecast MyRow variable. I need this to write a generic
SUB that can deal with rows of any table type.

Thanks

Regards
Jun 27 '08 #12

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

Similar topics

3
by: Kapil Khosla | last post by:
Hi, I have been trying to understand this concept for quite sometime now somehow I am missing some vital point. I am new to Object Oriented Programming so maybe thats the reason. I want to...
8
by: tweak | last post by:
I'm struggling with the concept of typecasting when setting up a TCP client. Here's a code snip (modified from W. Richard Stevens Unix Programming book) to demonstrate where I am struggling: ...
12
by: bwaichu | last post by:
What is the best way to handle this warning: warning: cast from pointer to integer of different size I am casting in and out of a function that requires a pointer type. I am casting an...
6
by: Nishu | last post by:
Hi all, What is difference between typecasting and casting? I used to think that both are same; but few days back someone pointed out here that these are different. Vague guess, Is it that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.