troubleshooting Question

VB.NET - converting datatypes in code

Avatar of colepc
colepc asked on
Visual Basic.NET
2 Comments1 Solution1303 ViewsLast Modified:
Hi All,
I'm needing to dynamically convert datatype from a string representation of SqlDbType (like "nchar" for SqlDbType.NChar) to a System.Type in code.

For example, I want to store a System.Type with a based on some value, like:
 dim mytype as System.Type
 If myvar = "nchar" then mytype = System.Type.GetType("System.String")

I want to then use mytype to convert some piece of data, like:
  dim myobject as Object
  myobject = CType(somevalue, mytype)

The CType() fails, however, with an excption saying that "Type 'mytype' is not defined."

 The app that this applies to is a data conversion app where I'm iterating through rows and columns converting them to another vendors'  application.  

My question is, can what I'm wanting to do be done?

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros