SQL Server bit資料類型

來源:互聯網
上載者:User

標籤:主鍵   取資料   als   pki   fine   資料庫表   顯示   資料   model   

bit值儲存為1/0,1代表true,0代表false
讀取資料庫資料時,可以直接用bool型讀取該欄位,會直接轉換為true/false

資料庫表結構

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]

實體類BitModel

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

讀取資料
採用dapper,封裝方法

public class DbManager<T> where T : class{    private static DbManager<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=;DataBase=;Uid=;pwd=;");        connection.Open();    }    public IEnumerable<T> QueryBySQL(string sql)    {        return connection.Query<T>(sql);    }    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);}

顯示資料

<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資料類型

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.