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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

user CType to convert to SqlDbType

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I am working on a class that will hopefully reduce my coding by dynamically building command objects and returning data tables.

I am stuck on the parameter type. I have stored proc that will retrieve a list of the parameters, their type, and lenght. the type is the text vaule (char, varchar, int, bit, datetime). I want to convert that value to the sqldbtype in vb.net to create the parameter collection for the sp.

The following is erroring out
[tt]While Reader.Read
GetParameters.Add(Reader.Item("Parameter"), CType(Reader.Item("DataType"), SqlDbType), Reader.Item("Length"))
End While[/tt]
I've thought of making a function of case statements that will return the sqldbtype, but that seems clunky. Is there a better way?
thanks for your help

Jason Meckley
Database Analyst
WITF
 
I think I may have found something. I need to turn the text value into that type object, then convert it a sqldbtype.

How can I take the text value and convert it to the type vaule?

Jason Meckley
Database Analyst
WITF
 
I actually just finished doing something very close to this. However, I'm not using strongly typed objects. If your interested I can email you the code.
It revolves around a ParamArray with three elements. ParamName, ParamValue and ParamDataType.
The Data Type is not required though. Just declare the new parameter with the Param Name and the Value. Assign them to the parameter object, add it to your command object and presto. It works.
 
I would be interested to see your project. My email address is jason_meckley@_NOSPAM_witf.org. Remove _NOSPAM_

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top