📄 cityaccessor.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DBaoBookingManagement.Entity;
namespace DBaoBookingManagement.DataAccess
{
/// <summary>
/// 对City表进行操作的类
/// </summary>
public class CityAccessor:DataAccessor
{
//查询所有城市
public DataTable QueryAll()
{
string sql = "select * from City";
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("查询所有城市时出现错误:"+ex.Message);
}
}
//根据城市ID查询城市
public DataTable QueryById(int id)
{
string sql = "select * from City where CityId="+id;
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("根据城市ID查询城市时出现错误:" + ex.Message);
}
}
//根据城市名称查询城市
public DataTable QueryByName(string cityName)
{
string sql = "select * from City where CityName='" + cityName + "'";
try
{
return base.Query(sql);
}
catch (Exception ex)
{
throw new Exception("根据城市名称查询城市时出现错误:" + ex.Message);
}
}
//插入城市
public bool Insert(City entity)
{
string cityName = entity.CityName;
string sql = "insert into City(CityName) values('" + cityName + "')";
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("插入城市时出现错误:"+ex.Message);
}
}
//修改城市
public bool Update(City entity)
{
int id = entity.CityId;
string cityName = entity.CityName;
string sql = "update City set CityName='" + cityName + "' where CityId="+id;
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("修改城市时出现错误:"+ex.Message);
}
}
//根据城市ID删除城市
public bool DeleteById(int id)
{
string sql = "delete City where CityId=" + id;
try
{
return base.ExecuteSqlNoneQuery(sql);
}
catch (Exception ex)
{
throw new Exception("删除City表时出现错误:"+ex.Message);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -