C#. NET according to the database 0,1 return the corresponding representative meaning "male", "female" and other issues

Source: Internet
Author: User

In general, we use data representation for database storage that determines strings, such as 0 for ' male ' 1 for ' female ', and for more character string storage, which saves more storage space for the database.
However, from the database reading angle, the original number must be represented by the data to be displayed in text.
Workaround: 1. From the database read out in the foreground interface binding time, traverse that variable, the data into text, such as 0-> "male"
The 2.select database is changed with a statement.
StringBuilder strsql=new StringBuilder ();
Strsql.append ("Select Resource_id,shop_id,resource_name,resource_time,resource_weight,resource_unit,resource_ State,resource_price,resource_type=case resource_type when 0 Then ' meat ' when 1 Then ' Seafood ' when 2 then ' vegetables ' when 3 then ' seasoning ' When 4 Then ' noodles ' when 5 then ' flour ' when 6 then ' egg ' else ' other ' END ');
Strsql.append ("from resource");

Format: Select Xx,yy,zz=case zz When 0 Then ' ... ' when 1 Then ' ... ' when ... else ' other ' end

from table_name;

Related Article

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.