Dim MyType as String = "numeric"
Dim sdtype As SqlDbType sdtype = DirectCast([Enum].Parse(GetType(SqlDbType), MyType), SqlDbType)
Not working for numeric. I want to know how to handle this data types. Thanks in advance.
The SqlDbType enumeration simply does not contain the value "numeric" so it's not possible to cast such string to that enum.
To avoid error, use such code: (C#, not familiar with VB.NET sorry)
SqlDbType dbType;
if (Enum.TryParse<SqlDbType>(myType, true, out dbType))
{
MessageBox.Show("type: " + dbType);
}
else
{
MessageBox.Show("invalid type: " + myType);
}
There are various numeric types available though, e.g. Float so changing the string to one of those should work just fine:
Dim MyType as String = "float"
All available data types for SQL Server database provider are:
BigInt Binary Bit Char DateTime Decimal Float Image Int Money NChar NText NVarChar Real UniqueIdentifier SmallDateTime SmallInt SmallMoney Text Timestamp TinyInt VarBinary VarChar Variant Xml Udt Structured Date Time DateTime2 DateTimeOffset
Any attempt to cast string not in this list will result in error.
Edit: on second thought looks like you are working with Access database? In such case, use OleDbType and not SqlDbType, just change the code to:
Dim sdtype As OleDbType sdtype = DirectCast([Enum].Parse(GetType(OleDbType), MyType), OleDbType)
And it should work, since OleDbType does contain "Numeric".