using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Collections;
using System.Data.SqlClient;
public class SqlHelper
{
#region 配置连接
private static SqlConnection connection;
static SqlConnection Connection
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings["数据库连接名"].ConnectionString;
if (connection == null)
{
connection = new SqlConnection(connectionString);
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Closed)
{
connection.Open();
}
else if (connection.State == System.Data.ConnectionState.Broken)
{
connection.Close();
connection.Open();
}
return connection;
}
}
#endregion
#region 设置SqlCommand
public static SqlCommand GetStoredProcCommond(string storedProcedure)
{
SqlCommand cmd = Connection.CreateCommand();
cmd.CommandText = storedProcedure;
cmd.CommandType = CommandType.StoredProcedure;
return cmd;
}
public static SqlCommand GetSqlStringCommond(string sqlQuery)
{
SqlCommand cmd = Connection.CreateCommand();
cmd.CommandText = sqlQuery;
cmd.CommandType = CommandType.Text;
return cmd;
}
#endregion
#region 增加参数
public static SqlCommand AddParameterCollection(SqlCommand cmd, SqlParameterCollection SqlParameterCollection)
{
foreach (SqlParameter SqlParameter in SqlParameterCollection)
{
cmd.Parameters.Add(SqlParameter);
}
return cmd;
}
public static void AddOutParameter(SqlCommand cmd, string parameterName, DbType dbType, int size)
{
SqlParameter SqlParameter = cmd.CreateParameter();
SqlParameter.DbType = dbType;
SqlParameter.ParameterName = parameterName;
SqlParameter.Size = size;
SqlParameter.Direction = ParameterDirection.Output;
cmd.Parameters.Add(SqlParameter);
}
public static void AddInParameter(SqlCommand cmd, string parameterName, DbType dbType, object value)
{
SqlParameter SqlParameter = cmd.CreateParameter();
SqlParameter.DbType = dbType;
SqlParameter.ParameterName = parameterName;
SqlParameter.Value = value;
SqlParameter.Direction = ParameterDirection.Input;
cmd.Parameters.Add(SqlParameter);
}
public static void AddReturnParameter(SqlCommand cmd, string parameterName, DbType dbType)
{
SqlParameter SqlParameter = cmd.CreateParameter();
SqlParameter.DbType = dbType;
SqlParameter.ParameterName = parameterName;
SqlParameter.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(SqlParameter);
}
public static SqlParameter GetParameter(SqlCommand cmd, string parameterName)
{
return cmd.Parameters[parameterName];
}
#endregion
#region 执行
public static DataSet ExecuteDataSet(SqlCommand cmd)
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
cmd.Dispose();
return ds;
}
public static DataTable ExecuteDataTable(SqlCommand cmd)
{
SqlDataAdapter da= new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dataTable = new DataTable();
da.Fill (dataTable);
cmd.Dispose();
da.Dispose();
return dataTable;
}
public static SqlDataReader ExecuteReader(SqlCommand cmd)
{
SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
cmd.Dispose();
return reader;
}
public static int ExecuteNonQuery(SqlCommand cmd)
{
int ret = cmd.ExecuteNonQuery();
cmd.Connection.Close();
cmd.Dispose();
return ret;
}
public static object ExecuteScalar(SqlCommand cmd)
{
object ret = cmd.ExecuteScalar();
cmd.Connection.Close();
cmd.Dispose();
return ret;
}
#endregion
}
相关推荐
从业10年的AI应用架构师:企业AI平台运营的4个核心经验,值得收藏
去年年底,我在某大型制造企业做AI咨询时,遇到了这样的场景:这不是个例。我接触过的10家企业中,有7家的AI平台都陷入了“技术自嗨”的陷阱——技术团队追求模型精度、功能完备性,却忽略了业务到底需要什么。如果你也遇到过类似问题:比如“模型准确率很高,但业务不买账”“AI项目上线后没人用”“投入产出比极低”,那么这篇文章的4个经验,可能会帮你避开这些坑。很多企业认为,AI平台就是“买一套工具+部署几个模型”。但实际上,企业AI平台的本质是“技术与业务的连接生态”:根据Gartner的报告,80%的企业AI项目失
SqlHelper类详解
SqlHelper 类实现详细信息 SqlHelper 类用于通过一组静态方法来封装数据访问功能。该类不能被继承或实例化,因此将其声明为包含专用构造函数的不可继承类。 在 SqlHelper 类中实现的每种方法都提供了一组一致的重载。这提供了一种很好的使用 SqlHelper 类来执行命令的模式,同时为开发人员选择访问数据的方式提供了必要的灵活性。每种方法的重载都支持不同的方法参数,因此
bcftools实战指南:从VCF文件处理到变异分析全流程解析
在基因组数据分析中,VCF(Variant Call Format)文件是存储基因序列变异信息的标准格式,广泛应用于群体遗传学和生物信息学研究。其核心原理是通过结构化文本记录SNP、INDEL等变异位点的基因型、质量值和注释信息。掌握高效处理VCF文件的技术,对于提升变异检测、数据清洗和下游分析的工作流效率具有重要价值。在生物信息学工具生态中,bcftools作为处理VCF/BCF文件的瑞士军刀,通过模块化设计实现了数据查询、过滤、统计和格式转换等核心功能。其流式处理架构支持管道化操作,能有效应对海量基因组
自己写的SqlHelper类
今天老师复习了ADO ,因为代码的重复使用问题,所以老师就让我们写了sqlhelper类 这是我写的sqlhelper public class SqlHelper { string constr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString; public
【自动驾驶】汽车智能驾驶计算芯片
本文介绍汽车智能驾驶计算芯片的软硬件要求、 可靠性和安全性要求、 性能要求,和相应的试验方法。除了用于汽车智能驾驶, 其他领域的计算芯片可参照执行。
【论文复现】水下单光子激光雷达设计 Sequential Multimodal Underwater Single
针对对慢速小水下目标进行远距离、高分辨率重建的需求,单光子激光雷达(LiDAR)目标重建技术的研究正在进行。本文报告了一种基于时空序列融合的顺序多模态水下单光子 LiDAR 自适应目标重建算法,该算法具有强大的信息提取和噪声过滤能力,能够从复杂的回波光子计数和空间像素关系中重建目标的深度和反射强度信息。该方法包括三个步骤:数据预处理、序列优化极值推断滤波以及图像优化协同变分策略,以实现复杂水下环境下的高质量目标重建。
SqlHelper类(C#)
大神可以绕道了... 目的:搜集SqlHelper类 自己写的一个SQLHelper类,如下: 编辑App.config节点,添加<connectionStrings>节点,并根据实际填上相应的参数 <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> ...
OpenDataLab 大模型训练数据集下载记录
大模型 训练数据集
常用SqlHelper类(C#)
SqlHelper类 public static class SqlHelper { //连接字符串 private static readonly string connStr = ConfigurationManager.ConnectionStrings["mssql"].ConnectionString; //1.执行增、删、...
YOLOv12改进专栏目录 | 本专栏持续更新500+篇内容 | 包含各种卷积、主干网络、各种注意力机制、检测头、损失函数、小目标检测改进、二次创新模块、独家创新等几百种创新点改进
《YOLOv12高效涨点改进专栏》提供500+创新改进方案,涵盖卷积、主干网络、注意力机制等模块优化,适用于检测、分割等任务。改进点来自顶会论文和个人经验,支持多种模型版本和任务场景。专栏包含详细教程、数据集增强、性能评估工具等,帮助科研人员快速实现模型优化和论文发表。提供完整运行项目和环境配置指导,适合计算机及相关专业研究人员使用,持续更新保障长期科研需求。
LE AUDIO---Volume Control Service
LE AUDIO---Volume Control Service
C# SQLHelper类
以前做的很多项目都用到了SQLHelper类今天心血来潮就像把他贴出来了 public class SQLHelper { private SqlConnection conn = null; private SqlCommand cmd = null; private SqlDataReader sdr = null; ...
破解现代反爬虫:JS加密、OB混淆与CSS反爬的实战攻防分析
摘要: 随着反爬技术的升级,JS加密、OB混淆和CSS反爬成为主流防护手段,阻碍传统爬虫获取数据。本文解析了这些技术的工作原理,并提出破解策略:通过模拟浏览器(如Selenium、Puppeteer)执行动态JS,逆向混淆代码,以及利用开发者工具突破CSS隐藏。针对复杂防护,开发者需结合技术分析与工具应用,如API接口抓取、动态渲染破解等,以应对不断演进的反爬机制。未来,爬虫攻防将持续升级,需保持技术敏锐性。
SqlHelper类的使用
机房重构进行了一小阶段,刚开始敲代码的时候,实现每一个功能都要在D层类中写一次数据据库连接(SqlConnection),SqlCommand,SqlDataReader语句,感到相当地麻烦。遇到这个问题后,就想到了面向对象的封装性,把D层中重复的SQL语句封装起来,以提高代码的复用性。通过上网查资料,知道了SqlHelper类和其使用方法。 SqlHelper类将数据库连接(SqlCo
迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)
迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)
汉书HE8,好用的汇编代码编写工具
汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大
SqlHelper类
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...
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
C#-SqlHelper类
使用C#编写SqlHelper类 无聊的周末,学习、编码无力。想找点事干但又不知道干点什么,猛然发现自己学过的SqlHelper快忘记了。于是乎虎躯一震心想怎能如此堕落下去,立马打开电脑,双手摸上键盘。写下此文作为学习过程中的复习,并分享出知识(顺便打发时间-^.^-)。 下面开始正文 这里以控制台程序为案例。首先我们需要先配置一下连接字符串,我们需要在app.config文件中增加如下节点...
VB摄像头监控
该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制
SqlHelper 帮助类
public class SQlhelper { private static string strConn = ConfigurationManager.ConnectionStrings["此处填写数据库连接字符串"].ConnectionString; /// <summary> /// 查询 /// </summary> /// <param name="sql"..
中文的SqlHelper.cs类
//这是在网上找的中文解释的SqlHelperusing System;using System.Configuration;using System.Data;using System.Data.SqlClient;using System.Collections; namespace com.DataAccess{ /// /// SqlHelper类提供很高的数据访问
C# sqlhelper 通用类
C# sqlhelper 通用类 using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.Sql...
C# SqlHelper类
C# SqlHelper类。
SqlHelper类的方法
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.
创建SQlHelper类
当我们在做项目的时候 要经常连接数据库 但数据库哪重复而又反复的代码让我们非常头疼 哪么我们就写一个SqlHelper类吧 吧连接数据库的代码封装到一个类中简化代码 下面以我的一个Asp.net的练习为例 这个程序有 三个功能 登陆 注册 和查看数据表的信息 下面是.aspx文件后台代码 已登录事件为例 protected void Button1_C
强大的SQLHelper类
在做机房收费系统的时候,曾经使用过Sqlhelper,当时对此内容理解不是很好,参照的是下篇的博客: vb.net—SQLHelper类的使用 而做过之后,当再次回首往事的时候,发现这个SQLHelper类并不是想象中的那么强大,其实可以在多扩充些。并且不好的地方是没有加入安全的事务机制,在此小编在前人的基础上,模仿别人写了一个类似的Sqlhelper。先看下类图。 此类一
微软的SQLHelper类
using System;using System.Data;using System.Xml;using System.Data.SqlClient;using System.Collections;namespace Microsoft{ /// /// The SqlHelper class is intended to encap
709



被折叠的 条评论
为什么被折叠?



