📄 categoryservice.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using MyBookShop.Models;
namespace MyBookShop.DAL
{
public static partial class CategoryService
{
public static Category GetCategoryById(int id)
{
string sql = "SELECT * FROM Categories WHERE Id = @Id";
using(SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@Id", id)))
{
if (reader.Read())
{
Category category = new Category();
category.Id = (int)reader["Id"];
category.Name = (string)reader["Name"];
reader.Close();
return category;
}
else
{
reader.Close();
return null;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -