SQL Server bit data type

Source: Internet
Author: User

The bit value is saved to 1/0, and 1 for true,0 represents false
When reading database data, the field can be read directly with the bool type and converted directly to True/false

database table Structure

create table [dbo].[ Bittable] ([PKID] [int] identity ( 1,1) not null, [Isdelete] [bit] NULL, PRIMARY key CLUSTERED ([PKID] ASC) with (pad_index = off, Statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = ON, Allow_page_locks = on) on [PRIMARY]) on [PRIMARY]            

Entity class Bitmodel

public class BitModel{    public int PKID { get; set; }    public bool IsDelete { get; set; }}

Reading data
Using dapper, encapsulation method

public class dbmanager<t> where t:class{private static dbmanager& Lt    t> instance;    private static Object _lock = new Object ();    private SqlConnection Connection; public static dbmanager<t> Instance {get {lock (_lock) {if                (instance = = null)                {instance = new dbmanager<t> ();        }} return instance; }} public DbManager () {connection = new SqlConnection ("Server=;D atabase=;        uid=;p wd=; "); Connection.    Open (); Public ienumerable<t> Querybysql (String sql) {return connection.    query<t> (SQL); The public bool Executeone (String sql) {if (connection.        Execute (SQL)! = 0) return true;    return false; }}
public ActionResult Bit(){    List<BitModel> list = new BLL.AboutDBManager().GetBitModel();    return View(list);}

Show data

<div>    <table>        <thead>            <tr>                <th>主键</th>                <th>是否删除</th>            </tr>        </thead>        <tbody>            @{                 foreach(var item in Model)                {                    <tr>                        <td>@item.PKID</td>                        <td>@item.IsDelete</td>                    </tr>                }            }        </tbody>    </table></div>

SQL Server bit data type

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.