三层结构之数据类层

/// <summary>
        
/// 增加一条数据
        
/// </summary>

        public int Add(Maticsoft.Model.EntryLog model)
        
{
            StringBuilder strSql
=new StringBuilder();
            strSql.Append(
"insert into EntryLog(");
            strSql.Append(
"Name,LandingDate)");
            strSql.Append(
" values (");
            strSql.Append(
"@Name,@LandingDate)");
            strSql.Append(
";select @@IDENTITY");
            SqlParameter[] parameters 
= {
                    
new SqlParameter("@Name", SqlDbType.VarChar,50),
                    
new SqlParameter("@LandingDate", SqlDbType.DateTime)}
;
            parameters[
0].Value = model.Name;
            parameters[
1].Value = model.LandingDate;

            
object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
            
if (obj == null)
            
{
                
return 1;
            }

            
else
            
{
                
return Convert.ToInt32(obj);
            }

        }

        
/// <summary>
        
/// 更新一条数据
        
/// </summary>

        public void Update(Maticsoft.Model.EntryLog model)
        
{
            StringBuilder strSql
=new StringBuilder();
            strSql.Append(
"update EntryLog set ");
            strSql.Append(
"Name=@Name,");
            strSql.Append(
"LandingDate=@LandingDate");
            strSql.Append(
" where ID=@ID ");
            SqlParameter[] parameters 
= {
                    
new SqlParameter("@ID", SqlDbType.Int,4),
                    
new SqlParameter("@Name", SqlDbType.VarChar,50),
                    
new SqlParameter("@LandingDate", SqlDbType.DateTime)}
;
            parameters[
0].Value = model.ID;
            parameters[
1].Value = model.Name;
            parameters[
2].Value = model.LandingDate;

            DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        }


        
/// <summary>
        
/// 删除一条数据
        
/// </summary>

        public void Delete(int ID)
        
{
            StringBuilder strSql
=new StringBuilder();
            strSql.Append(
"delete EntryLog ");
            strSql.Append(
" where ID=@ID ");
            SqlParameter[] parameters 
= {
                    
new SqlParameter("@ID", SqlDbType.Int,4)}
;
            parameters[
0].Value = ID;

            DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        }
阅读更多
文章标签: parameters null
个人分类: Asp.Net学习笔记
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭