資源描述:
《-.數(shù)據(jù)訪問層實(shí)現(xiàn)ⅱ-sql server代碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、數(shù)據(jù)庫輔助類SQLServerDALHelper.cs:?using?System;?using?System.Collections.Generic;?using?System.Configuration;?using?System.Data;?using?System.Data.SqlClient;??namespace?NGuestBook.SQLServerDAL?{?????///?????///?SQLServer數(shù)據(jù)庫操作助手????///?????public?sealed?class?SQLServ
2、erDALHelper????{????????///?????????///?用于連接SQLServer數(shù)據(jù)庫的連接字符串,存于Web.config中????????///?????????private?static?readonly?string?_sqlConnectionString?=?ConfigurationManager.AppSettings["SQLServerConnectionString"];????????///?????????///?執(zhí)行SQL命令,不返回任何值??
3、??????///?????????///?SQL命令????????public?static?void?ExecuteSQLNonQurey(string?sql)????????{????????????SqlConnection?connection?=?new?SqlConnection(_sqlConnectionString);????????????SqlCommand?command?=?new?SqlCommand(sql,connection);????????
4、????connection.Open();????????????command.ExecuteNonQuery();????????????connection.Close();????????}????????///?????????///?執(zhí)行SQL命令,并返回SqlDataReader????????///?????????///?SQL命令????????///?包含查詢結(jié)果的SqlDataReader???????
5、?public?static?SqlDataReader?ExecuteSQLReader(string?sql)????????{????????????SqlConnection?connection?=?new?SqlConnection(_sqlConnectionString);????????????SqlCommand?command?=?new?SqlCommand(sql,?connection);????????????connection.Open();????????????SqlDataReader?sqlReader?=?co
6、mmand.ExecuteReader();????????????//connection.Close();????????????return?sqlReader;????????}????????///?????????///?執(zhí)行存儲(chǔ)過程,不返回任何值????????///?????????///?存儲(chǔ)過程名????????///?參數(shù)????????publi
7、c?static?void?ExecuteProcedureNonQurey(string?storedProcedureName,IDataParameter[]?parameters)????????{????????????SqlConnection?connection?=?new?SqlConnection(_sqlConnectionString);????????????SqlCommand?command?=?new?SqlCommand(storedProcedureName,connection);????????????comman
8、d.CommandType?=?CommandType.StoredProced