欢迎来到天天文库
浏览记录
ID:14616505
大小:48.50 KB
页数:15页
时间:2018-07-29
《-.数据访问层实现ⅱ-sql server代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、数据库辅助类SQLServerDALHelper.cs: using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; namespace NGuestBook.SQLServerDAL { /// /// SQLServer数据库操作助手 /// public sealed class SQLServ
2、erDALHelper { /// /// 用于连接SQLServer数据库的连接字符串,存于Web.config中 /// private static readonly string _sqlConnectionString = ConfigurationManager.AppSettings["SQLServerConnectionString"]; /// /// 执行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(); } /// /// 执行SQL命令,并返回SqlDataReader /// /// SQL命令 /// 包含查询结果的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; } /// /// 执行存储过程,不返回任何值 /// /// 存储过程名 /// 参数 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
此文档下载收益归作者所有