468,133 Members | 1,152 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

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

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.
Nov 15 '05 #1
2 5044
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"tgif" <nf*@nospam.com> wrote in message
news:uy**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 15 '05 #2
tgif <nf*@nospam.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by gmccallum | last post: by
2 posts views Thread by Robert W. | last post: by
7 posts views Thread by djc | last post: by
reply views Thread by Elmo Watson | last post: by
1 post views Thread by JRD | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.