Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass a string value that is supposed to be an SqlDBType parameter

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I am have SqlDBType stored in my database as strings (varchar, int, etc). But the procedure want an enum (SqlDbType.Varchar, SqlDbType.int etc)

dbo.Parameters.Add(database.SetParameter("ProcedureName", SqlDbType.VarChar, 1000, name));

How do I use the string value I got from my database to call this function?

Thanks,

Tom
 
I tried a test:

test((SqlDbType)Enum.Parse(typeof(SqlDbType), "varchar"));

where the procedure is:

private void test(SqlDbType type)
{

}

and the error I get is:
***************************************************
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

Additional information: Requested value 'varchar' was not found.
***********************************************

Tom
 
I found out what it was.

Unfortunately, it is the inconsistency of Microsoft (as far as I can tell). In Sql Server, the case is all lower case when you get it from places like sys.systypes. But the enum for SqlDbType is in pascal case, so you can't use the value you get from Sql Server. You would have to lowercase the value from the enum to compare it to the name from sql server or use some type of dictionary setup.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top