Converting a string value to a db type (ex: tinyint)

  • Thread starter Thread starter tgif
  • Start date Start date
T

tgif

Can someone explain the format for converting a .NET datatype (such as
string or int) to a database type (such as tinyint, datetime) for use in a
SqlParameter.
 
tgif,

A tinyint in .NET is represented with the SqlByte structure. For this,
you can just pass values of type byte to the parameter, and an implicit
conversion from byte to SqlByte will be made.

If you are using strings, then you might want to call the static ToByte
method on the Convert class to convert the string to a byte value, and then
pass the byte value as the parameter.

Hope this helps.
 
tgif said:
Can someone explain the format for converting a .NET datatype (such as
string or int) to a database type (such as tinyint, datetime) for use in a
SqlParameter.

If you look at the SqlDbType enumeration, you'll see that for each
element of the enumeration it tells you which "normal" .NET type to use
in a parameter. Have a look at "Using Parameters with a DataAdapter" in
MSDN for examples and more information.
 
Back
Top