In MSSQL, convert text and ntext to int type data

Source: Internet
Author: User

Let's take a look at this Code:

 

1 <script language = "JavaScript" type = "text/JavaScript">
2 <! --
3 For (VAR I = 0; I <= 9; I ++)
4 {
5 Document. writeln ('<input type = "radio" name = "face" value = "' + I + '"' + (I = 2? 'Checked': '') + '/> ' + '& nbsp; & nbsp ;');
6 (I = 4) document. writeln ("<br/> ");
7}
8 -->
9 </SCRIPT>
10

 

It is used to implement the expression number.

Obtain the emoticon number in the background:

 

1 protected void sqldatasource1_inserting (Object sender, sqldatasourcecommandeventargs E)
2 {
3 E. Command. Parameters. Add (New sqlparameter ("@ face", convert. todecimal (request. Form ["face"]. tostring ())));
4 E. Command. Parameters. Add (New sqlparameter ("@ posttime", system. datetime. Now. tostring ()));
5}

 

 

 

You must know that the face field type in the database is int.

In this way, the conversion is successful.

However, convert. toint32 (request. Form ["face"]. tostring () will prompt that ntext and INT conversion is incorrect.

The original request. Form ["face"]. tostring () is of the ntext type. I am dizzy ....

 

I checked the information online:

 

In MSSQL, Enterprise Manager cannot directly convert text or ntext data to int type, which sometimes causes inconvenience.

In fact, a simple method can be used to convert text data to int type.

First, convert both text and ntext data to nvarchar,

Then convert nvarchar to int.

 

The same is true for decimal conversion.

 

Http://www.topfisher.com/phpbbs/simple/index.php? T28.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.