SQL Server bit数据类型
Posted 癫狂编程
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL Server bit数据类型相关的知识,希望对你有一定的参考价值。
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数据类型的主要内容,如果未能解决你的问题,请参考以下文章