namespace dal
{
public class olecado
{
private olehelp olehelper;
public olecado()
{
olehelper = new olehelp();
}
/// <summary>
/// 选出所有
/// </summary>
/// <returns>数据表</returns>
public DataTable selectall()
{
return olehelper.execquery("select * from category", CommandType.Text);
}
/// <summary>
/// 根据id选择
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public DataTable selectbyid(string id)
{
OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@id", id) };
return olehelper.execquery("select * from category where id=@id", paras, CommandType.Text);
}
/// <summary>
/// 根据内容选择
/// </summary>
/// <param name="catename"></param>
/// <returns></returns>
public DataTable selectbycatename(string catename)
{
OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@catename", catename) };
return olehelper.execquery("select * from category where catename like '%'+@catename+'%'", paras, CommandType.Text);
}
/// <summary>
/// 增加
/// </summary>
/// <param name="catename">名称</param>
/// <returns>逻辑</returns>
public bool insertcategory(string catename)
{
bool flag = false;
string cmdtext = "insert into category(catename) values(@catename)";
OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@catename", catename) };
int res = olehelper.execnonquery(cmdtext, paras, CommandType.Text);
if (res > 0)
{
flag = true;
}
return flag;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool deletecategory(string id)
{
bool flag = false;
string cmdtext = "delete from category where id=@id";
OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@id", id) };
int res = olehelper.execnonquery(cmdtext, paras, CommandType.Text);
if (res > 0)
{
flag = true;
}
return flag;
}
/// <summary>
/// 根据id更新
/// </summary>
/// <param name="id"></param>
/// <param name="catename"></param>
/// <returns></returns>
public bool fixcategory(string catename, string id)
{
bool flag = false;
string cmdtext = "update category set catename=@catename where id=@id";
OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@catename", catename), new OleDbParameter("@id", id) };
int res = olehelper.execnonquery(cmdtext, paras, CommandType.Text);
if (res > 0)
{
flag = true;
}
return flag;
}
/// <summary>
/// 判断是否存在
/// </summary>
/// <param name="catename"></param>
/// <returns></returns>
public bool exist(string catename)
{
bool flag = false;
OleDbParameter[] paras = new OleDbParameter[] { new OleDbParameter("@catename", catename) };
DataTable dt = olehelper.execquery("select * from category where catename=@catename", paras, CommandType.Text);
//DataTable dt = olehelper.execquery("select * from category where catename='" + catename + "'", CommandType.Text);
if (dt.Rows.Count > 0)
{
flag = true;
}
return flag;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;