Space is generated for data stored in the database, and space is saved to the database.

Source: Internet
Author: User

Space is generated for data stored in the database, and space is saved to the database.

Char (20): stores 20 characters. If it is not enough, it will be filled with spaces.

Nvarchar (2): stores up to 20 characters

At the same time, if you do not want to create spaces when inserting new or new data to the database, it is best to set the field varchar or nvarchar type:

        public bool Add(Model.Model_Companey model)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("insert into Companey (");            strSql.Append("C_OraName,C_Town,C_Trding,C_Postcode,C_Phone)");            strSql.Append(" values(");                           strSql.Append("@C_OraName,@C_Town,@C_Trding,lrtrim(@C_Postcode),lrtrim(@C_Phone))");            SqlParameter[] parameters = {                                        new SqlParameter("@C_OraName",SqlDbType.NVarChar,50),                                        new SqlParameter("@C_Town",SqlDbType.NVarChar,50),                                        new SqlParameter("@C_Trding",SqlDbType.NVarChar,50),                                        new SqlParameter("@C_Postcode",SqlDbType.NVarChar,10),                                        new SqlParameter("@C_Phone",SqlDbType.NVarChar,20)};            parameters[0].Value = model.C_OraName;            parameters[1].Value = model.C_Town;            parameters[2].Value = model.C_Trding;            parameters[3].Value = model.C_Postcode;            parameters[4].Value = model.C_Phone;            int rows = Helper.SQLHelper.ExcuteSQL(strSql.ToString(), parameters);            if (rows > 0)            {                return true;            }            else            {                return false;            }        }

 


How to remove spaces when calling data in the ACCESS database in ASP

Use t r I m!
1. If the field in your database is db_input
2. input box <input name = txtbox1.../>
...
3. rs ("db_input") = t r I m (request (txtbox1 ))
...
Rs. close
Set rs = nothing
'After tri m is added, the space contained in the txtbox1 string is truncated, and no space is written to the database.

If you want to remove spaces in <textarea> </textarea>, TRIM does not seem to work? Is there any other way? -----
Try to add this function:
Function HTMLEncode (fString)
FString = Replace (fString, CHR (13 ),"")
FString = Replace (fString, CHR (10) & CHR (10), "</P> <P> ")
FString = Replace (fString, CHR (10), "<BR> ")
HTMLEncode2 = fString
End function
Call it:
HTMLEncode (request ("textarea "))

Teach prawn: Well, I enter a piece of text from the Textarea text field, save it to the database, and then extract it to display it in the browser space-time frame or change it

The browser cannot identify common spaces and line breaks when parsing webpage files. It must use entity references such as spaces & nbsp; (to prevent the browser from parsing, A space is added here. html labels are used for line feed. <br/> or <p> </p> ..
You have to process the text when saving it to the database, and replace it with a symbol that the browser can recognize in spaces or line breaks.

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.