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

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
J

Jon Skeet [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top