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