NET三層架構(gòu)調(diào)用存儲過程實例的UI層代碼_第1頁
NET三層架構(gòu)調(diào)用存儲過程實例的UI層代碼_第2頁
NET三層架構(gòu)調(diào)用存儲過程實例的UI層代碼_第3頁
NET三層架構(gòu)調(diào)用存儲過程實例的UI層代碼_第4頁
NET三層架構(gòu)調(diào)用存儲過程實例的UI層代碼_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、NET三層架構(gòu)調(diào)用存儲過程實例的UI層代碼NET三層架構(gòu)調(diào)用存儲過程實例的UI層代碼首先 進(jìn)行數(shù)據(jù)庫操作1、建立一個數(shù)據(jù)庫【User】,建立一張數(shù)據(jù)表【UserInfo】包含四個字段 UserID int, UserName varchar(50), UserSex varchar(10), UserDesc varchar(50) 其中UserID為自動增長列2、創(chuàng)建存儲過程(1)、查找表中所有數(shù)據(jù)create procedure dbo.uInfo_selectasselect * from userInfo(2)、根據(jù)ID查找表中數(shù)據(jù)create procedure dbo.uInfo_

2、select_uiduID intasselect * from UserInfo where UserID = uID(3)、向表中插入數(shù)據(jù)create procedure dbo.uInfo_inSert uName varchar(50),uSex varchar(10),uDesc varchar(100)asinsert into userInfo(UserName,UserSex,UserDesc) values (uName,uSex,uDesc)(4)、更新表中數(shù)據(jù)create procedure dbo.uInfo_update uID int,uName varchar(5

3、0),uSex varchar(10),uDesc varchar(100)asupdate userInfo set UserName=uName,UserSex=uSex,UserDesc=uDesc where UserID = uID(5)、刪除表中某條記錄create procedure dbo.uInfo_delete uID intasdelete userInfo where UserID = uID二、DAL 里面類名叫:DAL_uInfo 要引用接口層IDAL (其他刪除什么的方法我也都寫了 ,本例只實現(xiàn)一個添加,其他的自己寫吧。)using System;using Sy

4、stem.Collections.Generic;using System.Text;using IDAL;using System.Data;using System.Data.SqlClient;using System.Configuration;namespace DALpublic class DAL_uInfo : IDAL_uInfo/獲取web.config中的鏈接字符串static string connStr = ConfigurationSettings.AppSettings"ConnDb"/ <summary>/ 查詢表中所有的數(shù)據(jù)/

5、</summary>/ <returns></returns>public DataSet uinfo_select()DataSet ds = new DataSet();using (SqlConnection conn = new SqlConnection(connStr)tryconn.Open();SqlCommand comm = new SqlCommand("uInfo_select", conn);comm.CommandType = CommandType.StoredProcedure;SqlDataAdapter

6、 da = new SqlDataAdapter(comm);da.Fill(ds);return ds;catch (SqlException ex)throw new Exception(ex.Message);/ <summary>/ 查詢表中所有的數(shù)據(jù)/ </summary>/ <param name="ID">根據(jù)ID</param>/ <returns></returns>public DataSet uinfo_select(int ID)using (SqlConnection conn

7、 = new SqlConnection(connStr)DataSet ds = new DataSet();tryconn.Open();SqlCommand comm = new SqlCommand("uInfo_select_uid", conn);comm.CommandType = CommandType.StoredProcedure;SqlParameter puID = new SqlParameter("uID", SqlDbType.Int);puID.Value = ID;comm.Parameters.Add(puID);Sq

8、lDataAdapter da = new SqlDataAdapter(comm);da.Fill(ds);return ds;catch (SqlException ex)throw new Exception(ex.Message);/ <summary>/ 向表中插入數(shù)據(jù)/ </summary>/ <param name="uName">用戶名稱</param>/ <param name="uSex">性別</param>/ <param name="uDes

9、c">信息</param>public void uinfo_insert(string uName, string uSex, string uDesc)using (SqlConnection conn = new SqlConnection(connStr)tryconn.Open();SqlCommand comm = new SqlCommand("uInfo_inSert", conn);comm.CommandType = CommandType.StoredProcedure;SqlParameter puName = new S

10、qlParameter("uName", SqlDbType.VarChar, 50);SqlParameter puSex = new SqlParameter("uSex", SqlDbType.VarChar, 10);SqlParameter puDesc = new SqlParameter("uDesc", SqlDbType.VarChar, 50);puName.Value = uName;puSex.Value = uSex;puDesc.Value = uDesc;comm.Parameters.Add(puNam

11、e);comm.Parameters.Add(puSex);comm.Parameters.Add(puDesc);comm.ExecuteNonQuery();catch (SqlException ex)throw new Exception(ex.Message);/ <summary>/ 更新表中數(shù)據(jù)/ </summary>/ <param name="uID">用戶ID</param>/ <param name="uName">名稱</param>/ <param n

12、ame="uSex">性別</param>/ <param name="uDesc">信息</param>public void uinfo_update(int uID, string uName, string uSex, string uDesc)using (SqlConnection conn = new SqlConnection(connStr)tryconn.Open();SqlCommand comm = new SqlCommand("uInfo_updata", conn

13、);comm.CommandType = CommandType.StoredProcedure;SqlParameter puName = new SqlParameter("uName", SqlDbType.VarChar, 50);SqlParameter puSex = new SqlParameter("uSex", SqlDbType.VarChar, 10);SqlParameter puDesc = new SqlParameter("uDesc", SqlDbType.VarChar, 50);SqlParamet

14、er puID = new SqlParameter("uID", SqlDbType.Int);puName.Value = uName;puSex.Value = uSex;puDesc.Value = uDesc;puID.Value = uID;comm.Parameters.Add(puName);comm.Parameters.Add(puID);comm.Parameters.Add(puDesc);comm.Parameters.Add(puSex);comm.ExecuteNonQuery();catch (SqlException ex)throw ne

15、w Exception(ex.Message);/ <summary>/ 刪除表中數(shù)據(jù)/ </summary>/ <param name="uID">用戶ID</param>public void uinfo_delete(int uID)using (SqlConnection conn = new SqlConnection(connStr)tryconn.Open();SqlCommand comm = new SqlCommand("uInfo_delete", conn);comm.Command

16、Type = CommandType.StoredProcedure;SqlParameter puID = new SqlParameter("uID", SqlDbType.Int);puID.Value = uID;comm.Parameters.Add(puID);comm.ExecuteNonQuery();catch (SqlException ex)throw new Exception(ex.Message);三、BLL里面類名叫:BLL_uInfousing System;using System.Collections.Generic;using Sys

17、tem.Text;using System.Data;namespace BLLpublic class BLL_uInfoIDAL.IDAL_uInfo dal = new DAL.DAL_uInfo();/ <summary>/ 查詢表中所有的數(shù)據(jù)/ </summary>/ <returns></returns>public DataSet uinfo_select()return dal.uinfo_select();/ <summary>/ 查詢表中所有的數(shù)據(jù)/ </summary>/ <param name

18、="ID">根據(jù)ID</param>/ <returns></returns>public DataSet uinfo_select_id(int ID)return dal.uinfo_select(ID);/ <summary>/ 向表中插入數(shù)據(jù)/ </summary>/ <param name="uName">用戶名稱</param>/ <param name="uSex">性別</param>/ <param

19、 name="uDesc">信息</param>public void uinfo_insert(string uName, string uSex, string uDesc)dal.uinfo_insert(uName, uSex, uDesc);/ <summary>/ 更新表中數(shù)據(jù)/ </summary>/ <param name="uID">用戶ID</param>/ <param name="uName">名稱</param>/ &l

20、t;param name="uSex">性別</param>/ <param name="uDesc">信息</param>public void uinfo_update(int uID, string uName, string uSex, string uDesc)dal.uinfo_update(uID, uName, uSex, uDesc);/ <summary>/ 刪除表中數(shù)據(jù)/ </summary>/ <param name="uID">用戶

21、ID</param>public void uinfo_delete(int uID)dal.uinfo_delete(uID);四、IDAL(接口層)類名:IDAL_uInfousing System;using System.Collections.Generic;using System.Text;using System.Data.SqlClient;using System.Data;namespace IDALpublic interface IDAL_uInfo/ <summary>/ 查詢表中所有的數(shù)據(jù)/ </summary>/ <re

22、turns></returns>DataSet uinfo_select();/ <summary>/ 查詢表中所有的數(shù)據(jù)/ </summary>/ <param name="ID">根據(jù)ID</param>/ <returns></returns>DataSet uinfo_select(int ID);/ <summary>/ 向表中插入數(shù)據(jù)/ </summary>/ <param name="uName">用戶名稱</

23、param>/ <param name="uSex">性別</param>/ <param name="uDesc">信息</param>void uinfo_insert(string uName, string uSex, string uDesc);/ <summary>/ 更新表中數(shù)據(jù)/ </summary>/ <param name="uID">用戶ID</param>/ <param name="uName

24、">名稱</param>/ <param name="uSex">性別</param>/ <param name="uDesc">信息</param>void uinfo_updata(int uID, string uName, string uSex, string uDesc);/ <summary>/ 刪除表中數(shù)據(jù)/ </summary>/ <param name="uID">用戶ID</param>vo

25、id uinfo_delete(int uID);五、UI1、界面代碼<% Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CunchuDiaoyong._Default" %><!DOCTYPE html PUBLIC "-/W3C/DTD XHTML 1.0 Transitional/EN" "/TR/xhtml1/DT

26、D/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml" ><head runat="server"><title>無標(biāo)題頁</title></head><body><form id="form1" runat="server"><div><asp:TextBox ID="TextBox1" runa

27、t="server"></asp:TextBox><br /><br /><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br /><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br /><br /><asp:

28、Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="添 加" /></div></form></body></html>2、后臺代碼using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;usin

29、g System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;namespace CunchuDiaoyongpublic partial class _Default : System.Web.UI.Pageprotected void Page_Load(object sender, EventArgs e)protected void btnAdd_Click(object sender, EventArgs e)string a = TextBox1.Text.Trim();string b = TextBox2.Text.Trim();string c = TextBox3.Text.Trim();BLL.BLL_uInfo User = new BLL.BLL_uInfo();User.uinfo_insert(a, b, c);六、Web.config<?xml version="1.0" encoding="utf-8"?><configuration><

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論