标签:
对于三层的概念查也查了,看也看了,下面是我找的一个关于三层的简单实例,真正看一下它是如何具体实现的.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace model { public class User { public User() { } private string _name; public string name { set { _name = value; } get { return _name; } } } }
<add name="ConnectionString" connectionString="Data Source=localhost;Initial Catalog=tester;User ID=sa;Password=123456" providerName="System.Data.SqlClient" />
using System; using System.Collections.Generic; using System.Linq; using System.Text; using model; using System.Data; using System.Configuration; using System.Data.SqlClient; namespace DAL { public class UserDB { public bool User_add(model.User model) { string setting = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); SqlConnection myconn=new SqlConnection(setting); myconn.Open(); SqlCommand cmd=new SqlCommand("insert into dbo.[user]([name]) values(@name)",myconn); cmd.Parameters.AddWithValue("@name", model.name); if (cmd.ExecuteNonQuery()>0) { return true; } else { return false; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using DAL; namespace BLL { public class userBLL { DAL.UserDB db = new UserDB(); public bool addUser(model.User model) { return db.User_add(model); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using BLL; using model; namespace 登陆 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { model.User thisUser = new User(); thisUser.name = TB_username.Text.ToString(); BLL.userBLL uB = new userBLL(); if (uB.addUser (thisUser)) { MessageBox.Show ("true"); } else { MessageBox.Show ("false"); } } } }
标签:
原文地址:http://www.cnblogs.com/starksoft/p/3870659.html