BLL应如何调用DAL。在DAL中的以下代码中 [英] how BLL should call the DAL. in the following code in DAL

查看:63
本文介绍了BLL应如何调用DAL。在DAL中的以下代码中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

INSERT:

INSERT:

public bool Insert(User user)
       {
           SqlConnection con = new SqlConnection(new Connection().GetConnectionString());

           string sql = "INSERT INTO User (Email) values (@Email)";
           con.Open();
           SqlCommand cmd = new SqlCommand(sql, con);
           cmd.Parameters.AddWithValue("@Email", SqlDbType.VarChar);
           cmd.Parameters["@Email"].Value = User.email;
           //cmd.ExecuteNonQuery();

           bool isInserted = cmd.ExecuteNonQuery() > 0;
           return isInserted;

       }



更新:


UPDATE:

public bool Update(User user)
       {
           SqlConnection con = new SqlConnection(new Connection().GetConnectionString());

           string sql = "UPDATE INTO User (Email) values (@Email)";
           con.Open();
           SqlCommand cmd = new SqlCommand(sql, con);
           cmd.Parameters.AddWithValue("@Email", SqlDbType.VarChar);
           cmd.Parameters["@Email"].Value = User.email;
           //cmd.ExecuteNonQuery();

           bool isUpdated = cmd.ExecuteNonQuery() > 0;
           return isUpdated;

       }

推荐答案

总是相反。 BLL应该调用DAL。
It is always the other way round. BLL should call the DAL.


这篇关于BLL应如何调用DAL。在DAL中的以下代码中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆