473,795 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5481
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.co m

"tgif" <nf*@nospam.com > wrote in message
news:uy******** ******@TK2MSFTN GP10.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2556
by: Gavin | last post by:
Hi, I would like to convert a dollar amount ($1,500) to represent Fifteen hundred dollars and 00/100 cents only for SQL reporting purposes. Is this possible and can I incorporate the statement into an existing left outer join query. Thanks in advance, Gavin
5
5866
by: gmccallum | last post by:
I am trying to convert the value of a string to a defined enum value such as follows. public enum MyEnum { One, Two }; string MyString = "One"; // or even this is fine string MyString2 = "MyEnum.One"; // This doesn't work (obviously), but effectively this
2
6810
by: Robert W. | last post by:
In a posting earlier this year I found a simple approach to convert a string to a particular Enum value. The one line solution looked like this: MyEnum ConvertedString = (MyEnum) Enum.Parse(typeof(MyEnum), MyString, true); This is fine if one wants to hardcode each and every Enum in an If-ElseIf or Select-Case construct but I'm wondering if there's a way to do it generically? I have a situation where I'm using reflection to set a...
7
1632
by: djc | last post by:
I have typically always used one of the VB CType functions (not CType itself but CInt, CString, etc...) to cast/convert an input value to its proper type before passing it as a parameter to a SQL stored procedure. I recently came accross one I did not know how to handle though... TinyInt. I have an SQL field of type TinyInt which is an 8bit integer. I came accross a ToInt16() vb function but not one for an 8 bit 'TinyInt'. So I next just...
9
7136
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but when I tried the program on the Win98 system it will be running on, I get the following error: Cast from string "2076719" to type 'Long' is not valid I am not sure why I only get this error on the Win98 system or how to go about correcting...
0
1976
by: Elmo Watson | last post by:
I am having all kinds of problems with a Stored Proc I'm trying to run, with the error I'm getting above. First - the way I'm reading it - the database EXPECTS a TinyInt - and it thinks I'm giving it a varchar input - right? If that's so - there's only one field in the table that uses tinyInt - and I've double checked: cmd.Parameters.Add(New OleDbParameter("@idMarketingRepType",
1
4279
by: JRD | last post by:
Greetings, I would like to search down through the following xml string that is returned to my calling app via a webservice. What I am trying to get is the following section from the xml string <component><section><code code="8716-3" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC" displayName="VitalSigns" /><title>Vital...
9
4003
by: seep | last post by:
hi i m finding following error on the code that i wants to use to get all record from table via store procedure with paging. the error is : Input string was not in a correct format. after a hectic struggle still i dont know 1--who can i solve it and 2--where should i have to place the function GETDATA . who is it possible to keep all the functions in a separate file and to call that file in required page. here is the...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.