我的代码是这样的:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace ebusiness.Components
{
public class Category
{
public Category()
{ }
public DataTable GetCatgories()
{
try
{
ebusiness.Common.DataAccess DataAs = new ebusiness.Common.DataAccess();
DataTable DT = DataAs.CreateDataTable("select*from[Categories]");
return (DT);
}
catch (Exception ex)
{
ebusiness.Common.SystemError.SystemLog(ex.Message);
throw new Exception(ex.Message, ex);
}
}
public bool DeleteCategory(int category_id)
{
try
{
ebusiness.Common.DataAccess DataAs = new ebusiness.Common.DataAccess();
bool flag = DataAs.ExecSql("delete from [Categories] where category_id =" + category_id);
return (flag);
}
catch (Exception ex)
{
ebusiness.Common.SystemError.SystemLog(ex.Message);
throw new Exception(ex.Message, ex);
}
}
public DataTable GetCategory(string name)
{
try
{
ebusiness.Common.DataAccess DataAs = new ebusiness.Common.DataAccess();
string strSQL = "select * from[Categories] where name = '" + name + "'";
DataTable DT = DataAs.CreateDataTable(strSQL);
return (DT);
}
catch (Exception ex)
{
ebusiness.Common.SystemError.SystemLog(ex.Message);
throw new Exception(ex.Message, ex);
}
}
public bool hasCategory(string name)
{
DataTable DT = GetCategory(name);
if (DT.Rows.Count > 0)
return true;
else
return false;
}
public bool AddCategory(string name)
{
try
{
ebusiness.Common.DataAccess DataAs = new ebusiness.Common.DataAccess();
bool flag = DataAs.ExecSql("insert into [Categories] values('" + name + "')");
return (flag);
}
catch (Exception ex)
{
ebusiness.Common.SystemError.SystemLog(ex.Message);
throw new Exception(ex.Message, ex);
}
}
public bool UpdateCategroy(int category_id, string name)
{
try
{
ebusiness.Common.DataAccess DataAs = new ebusiness.Common.DataAccess();
bool flag = DataAs.ExecSql("update [Categories] set name ='" + name + "'where category_id = " + category_id);
return (flag);