最新的SqlHelper 类】的更多相关文章

最新的SqlHelper 类 摘自:http://www.cnblogs.com/sufei/archive/2010/01/14/1648026.html using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Collections; namespace SystemDAO {     /// …
上一篇文章讲了简易版的SqlHelper类的编写,我们在这里就上一篇文章末尾提出的问题写出解决方案. sql语句注入攻击已经是众所周知的了.我们如何在C#中保护自己的数据库不被这样的方式攻击呢? 不用担心,c#中已经提供了很好的解决方案,那就是 SqlParameter类. 如何使用它呢? class SqlHelper{ public object ExecuteScalar(string sql,Parameter [] parameters)//这一这里增加了一个参数,是个Paramete…
在这次做项目中,我对自己最满意的就是封装了一下SQLHelper类,我对自己感到骄傲主要是 我是初学者,我刚开始不知道可以这样做,我只是想着试着去这样做了,结果真的可以,所以我 在我的模块就自己封装了一个SQLHelper,虽然下面用的这个不是很好,但是基本上满足需求, 因为似乎所有类都能转换为String,所以就用String数组来补充sql语句中的可变参数,但是有 一个问题,就是在调用的时候第二个参数必须为null,或者String数组,如果只有一个参数,也 要用String数组的形式传进去…
在.net平台的项目开发中,凡是用到数据库交互的,都有必要了解SqlHelper类的原理. 步骤一: 我就拿WPF项目开发作为例子.首先要新建一个App.config(应用程序配置文件).注意,在VS中默认新建的文件名为App1.config.必须要把名字改回来.你不管在App1.config里写什么,项目都不会加载.文件名必须是App.config.当然,如果你做的是web开发,可以新建一个web.config配置文件,原理相同. 新建这个配置文件用来写入与数据库连接的必要信息.如服务器地址,…
自己写sqlhelper类 using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; namespace birthday { /// <summary> /// SqlHelper /// </summary> [Se…
今天复习了一次ADO.NET基础,整理一下自己的认为的重点: 编写SqlHelper类,方便我们执行数据库语句,这时可以直接调用封装在SqlHelper类的方法.现在大多数公司面试的时候,给你的面试题都会要你自己手写一个SqlHelper的类,这考的是自己的基本功,如果一个根基不牢固的开发人员,你写的代码肯定好不到哪里去. 下面是SqlHelper的演示代码,一定要熟练: public static SqlHelper { //这里定义一个字符串变量,把数据库连接字符串赋值给它,也可以把连接字符…
在.NET平台中,C#语言一般使用ADO.NET组件来操作Sqlserver数据库,通过ADO.NET组件可以实现连接数据库.查询数据集.执行SQL语句以及关闭数据库连接等操作,为此网上有很多开发者自定义封装好的SqlHelper类供使用,其实微软官方自己也提供了一个比较完整的Sqlserver数据库操作帮助类SqlHelper,该帮助类文件中包含了详细的中文注释. 该SqlHelper类比较完整,代码量比较多,因此博主加了个链接提供个读者下载,百度网盘下载地址:SqlHelper类. 备注:此…
数据库操作类真的没有必要自己去写,因为成熟的类库真的非常完善了,拿来直接用就好,省时省力. 本文就为大家介绍微软官方的程序PetShop4.0中的SqlHelper类,先来做一下简单的介绍,PetShop是一个范例,微软用它来展示.Net企业系统开发的能力. 那SqlHelper中封装了哪些方法呢? 里面的函数一堆,常用的就那几个,无非就是增删改查嘛,来看下几种常用的函数: 1.ExecuteNonQuery 执行增删改2.ExecuteReader 执行查询3.ExecuteScalar 返回…
/// <summary> /// SqlHelper类 by zy 2016-3-11 /// </summary> public sealed class SqlHelper { //如果项目中只连接了一个数据库 那么可以在此定义一个固定的连接字符串 private static string connectionStr = ConfigurationManager.ConnectionStrings["SQLConnString1"].Connection…
本文实例讲述了C#基于SQLiteHelper类似SqlHelper类实现存取Sqlite数据库的方法.分享给大家供大家参考.具体如下: 这个类不是我实现的,英文原文地址为http://www.eggheadcafe.com/articles/20050315.asp,这里修改了原文中分析sql语句参数的方法,将方法名修改为AttachParameters,将其修饰符修改为private,并直接传递command到这个方法,直接绑定参数到comand.修改后的代码如下 using System;…
1.简单说明一下,一般情况下,数据库连接字符串是在App.config文件中进行配置,然后再在代码中进行引用.因此,我们在这里先看一下App.config文件. 首先看需要添加的内容: 参数说明: name:表示键值,在代码中需要通过这键值来找到对应的连接字符串信息. connectionString:链接数据库的字符串信息.Server:数据库服务器,Database:数据库,uid:数据库账户名,pwd:数据库密码 <?xml version="1.0" encoding=&…
// 一个自用的 SqlHelper 类 利用了刚学习到的 扩展方法 http://technet.microsoft.com/zh-cn/bb383977 /// <summary> /// The SqlHelper class is intended to encapsulate high performance, /// scalable best practices for common uses of SqlClient. /// </summary> public a…
/// <summary> /// 类说明:公共的数据库访问访问类 /// 编码日期:2010-4-22 /// 编 码 人:苏飞 /// 联系方式:361983679 Email:[url=mailto:sufei.1013@163.com]sufei.1013@163.com[/url] Blogs:[url=http://www.sufeinet.com]http://www.sufeinet.com[/url] /// 修改日期:2013-08-15 /// </summary&…
无聊的周末,学习.编码无力.想找点事干但又不知道干点什么,猛然发现自己学过的SqlHelper快忘记了.于是乎虎躯一震心想怎能如此堕落下去,立马打开电脑,双手摸上键盘.写下此文作为学习过程中的复习,并分享出知识(顺便打发时间-^.^-). 下面开始正文 这里以控制台程序为案例.首先我们需要先配置一下连接字符串,我们需要在app.config文件中增加如下节点: <connectionStrings> <add name="Sql" connectionString=&…
sql公共类: namespace Job.Common { public enum DataOption { Select = , Create, Update, Delete, Login } public sealed class SqlHelper { #region public ConnectionString private static string _defaultConnectionString; private static string _policyConnection…
#region 私有构造函数和方法 private SqlHelper() { } /// <summary> /// 将SqlParameter参数数组(参数值)分配给SqlCommand命令. /// 这个方法将给任何一个参数分配DBNull.Value; /// 该操作将阻止默认值的使用. /// </summary> /// <param name="command">命令名</param> /// <param name=…
using System;using System.Collections.Generic;using System.Text;using System.Collections;using System.Data.SqlClient;using System.Data;using System.Configuration; public class SQLHelper { //取得数据库连接web.config 中配置  public static readonly string Connect…
using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.Collections; namespace Book.DAL { /// <summary> /// SqlServer数据访问帮助类 /// </summary> public sealed class SqlHelper { #region 私有构造函数和方法 private SqlHelpe…
using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace BloodWeb.Common { /// <summary>…
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Data.SqlClient;using System.Configuration;using System.Data;namespace Dal{    public class SqlHelper    {        /// <summary>…
WP8出来好一段时间了,新出的AudioVideoCaptureDevice类自定义功能比WP7的CaptureSource强大的多,但网上比较全面的中文实例还比较少,分享一个最近做的小实例给大家参考. 一.实现的功能 1.实现视频和音频的采集并保存 2.允许切换前后摄像头 3.录像过程中可以随时截图 4.录像后视频播放 二.需要的权限 1.需要访问前后摄像头的权限(ID_CAP_ISV_CAMERA) 2.需要访问麦克风的权限(ID_CAP_MICROPHONE) 三 .UI部分 1.使用一个…
1.使用Connection连接数据库的步骤: (1).添加命名空间 System.Data.SqlClient(注意:初学者经常会忘记) (2)定义连接字符串.连接SQL Server 数据库时: server=服务器名:database=数据库名:uid=用户名:pwd=密码:例如:要连接本机上的StudentManagement数据库,用户名为sa,密码为111 string connString="server=.;database=StudentManagement:uid=sa:pw…
SqlHelper.cs public static class SqlHelper { private static readonly string conStr = ConfigurationManager.ConnectionStrings["sql"].ConnectionString; public static int ExecuteNonQuery(string sql, CommandType cmdType, params SqlParameter[] pms) {…
下面我们直接用可变长度参数的方式写一个完整的SqlHelper增删改public static int ExecuteNonQuery(string sql,params Parameter[] parameters){ using(SqlConnection conn = new SqlConnection(conStr)) { conn.Open(); using(SqlCommand cmd = conn.CreateCommand()) { cmd.CommandText=sql; cm…
从视频上学习到的WPF连接数据库的方法 需要配置一个 configuration 文件,包含 SQL instance 的相关信息 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.Data.SqlClient; using System.Data; namespace ADO { class…
代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 // =============================================================================== // Microsoft Data Access Application Block for .NET // http://m…
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RuPengWang.DAL { public class SqlHelper { privat…
using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; using System.Data; using Microsoft.Win32; namespace SqlHelp { /// <summary> /// 定义SqlParameter所需的参数对象 /// </summary> public class Parameter { /// &…
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Data; using System.Configuration; namespace WpfApplication1 { public class SqlHelper { private static string connStr = Con…
在使用Sqlhelper类时,出现cs0103错误 当前上下文中不存在名称configurationmanager 解决方案,除了using引用using System.Configuration外,还需在解决方案资源管理器里的“引用”中添加“System.Configuration”.…