SqlParameter 2
SqlParameter
string strSql = "Insert into News(TypeId,NewsCaption,NewsContent) values(@TypeId,@NewsCaption,@NewsContent)";
SqlParameter[] paras ={
new SqlParameter("@TypeId",SqlDbType.Int),
new SqlParameter("@NewsCaption",SqlDbType.NVarChar,200),
new SqlParameter("@NewsContent",SqlDbType.NText)
};
paras[0].Value = typeId;
paras[1].Value = caption;
paras[2].Value = content; int rows = new SqlHelp().ExecuteNonQuery(strSql, paras); public SqlHelp() {
connString = ConfigurationManager.AppSettings["sqlServer2005DbName"]; } public int ExecuteNonQuery(string strQuery, SqlParameter[] paras) {
int rows = 0; //影响行数
try {
using (SqlConnection conn = new SqlConnection(connString)) {
using (SqlCommand command = new SqlCommand()) {
PrepareCommand(conn, command, strQuery, paras);
rows = command.ExecuteNonQuery();
return rows;
}
}
} catch {
throw;
}
} //带参数的DML操作
private void PrepareCommand(SqlConnection conn, SqlCommand command, string strQuery, SqlParameter[] paras) {
if (conn.State != ConnectionState.Open) {
conn.Open();
}
command.Connection = conn;
command.CommandText = strQuery;
command.CommandType = CommandType.Text;
if (paras != null) {
foreach (SqlParameter parm in paras)
command.Parameters.Add(parm);
}
}
SqlParameter 2的更多相关文章
- SQL参数化查询自动生成SqlParameter列表
string sql = @"INSERT INTO stu VALUES (@id,@name) "; 参数化查询是经常用到的,它可以有效防止SQL注入.但是需要手动去匹配参数@ ...
- SqlParameter的感悟
1.在更新DataTable或是DataSet时,如果不采用SqlParameter,那么当输入的Sql语句出现歧义时,如字符串中含有单引号,程序就会发生错误,并且他人可以轻易地通过拼接Sql语句来进 ...
- Ibatis.net总是报:【ExecuteStoreCommand SqlParameterCollection 中已包含 SqlParameter】(转)
今天很奇怪调用EF的ExecuteStoreCommand 出现了个这样的错误,怎么也调试不过,痛定思痛 原来 command被连着调用了而没有销毁掉 public static DataTabl ...
- Send SqlParameter to Dapper
Question: I' using Dapper in my project. I have a list of SqlParameters and I want to send it to Dap ...
- Ado.net 三[SQL注入,DataAdapter,sqlParameter,DataSet]
1.SQL注入:SQL注入攻击是web应用程序的一种安全漏洞,可以将不安全的数据提交给运用程序,使应用程序在服务器上执行不安全的sql命令.使用该攻击可以轻松的登录运用程序. 例如:该管理员账号密码为 ...
- 关于SqlParameter设定size和value
1.设定size 字段定义:column [Text] nvarchar(max) NULL 设定字段最大长度: new SqlParameter("@Text",SqlDbTyp ...
- SqlParameter设定value为0却变成null
直接MSDN:http://msdn.microsoft.com/zh-cn/library/0881fz2y(VS.80).aspx 当在 value 参数中指定 Object 时,SqlDbTyp ...
- sqlhelper sqlparameter 实现增删改查
这是sqlHelper.cs类,类内里封装了方法 using System; using System.Collections.Generic; using System.Linq; using Sy ...
- 用SqlParameter 给SQL传递参数
1.数据访问层 using的用法: 01.可以using System;导命名控空间 02.using 的语法结构 using(变量类型 变量名 =new 变量类型()) { } 案例: 03.us ...
- SqlParameter中的size
SqlParameter中size对于需要指定大小的数据库中的数据类型参数有影响[如nvarchar],如果对于这些类型没有指定size则会默认根据赋的值进行推导应该指定的size,而对于那些大小固定 ...
随机推荐
- Angular入门教程三
4.6指令(directive) 通过使用模板,我们可以把model和controller中的数据组装起来呈现给浏览器,还可以通过数据绑定,实时更新视图,让我们的页面变成动态的. 模板中可以使用的东西 ...
- 设置Web AppBuilder的HTTP代理
在使用Web AppBuilder快速搭建webgis应用时,我们往往需要访问外部互联网的在线gis服务资源.假如要通过代理服务器才能访问互联网的在线gis服务资源,那么则需要预先配置web appb ...
- 移动 App 接入 QQ 登录/分享 图文教程
移动 App 接入 QQ 登录/分享 图文教程 这里先要提两个平台,腾讯开放平台和 QQ 互联平台: (一)腾讯开放平台 官网地址:https://open.tencent.com/ 介绍:腾讯开放平 ...
- Monte Calro Tree Search (MCTS)
https://blog.csdn.net/natsu1211/article/details/50986810, 感谢分享! Intro最近阿法狗和李师师的人机大战着实火了一把,还顺带捧红了柯杰,古 ...
- ubuntu16下面安装vmware tools后仍然未全屏问题
1.默认下载ubuntu16的iso镜像后,自带的有vmtools.解压 tar -xzvf VMwareTools-10.0.6-3595377.tar.gz 进入解压目录. 执行:sudo ./ ...
- 对数损失函数(Logarithmic Loss Function)的原理和 Python 实现
原理 对数损失, 即对数似然损失(Log-likelihood Loss), 也称逻辑斯谛回归损失(Logistic Loss)或交叉熵损失(cross-entropy Loss), 是在概率估计上定 ...
- 关闭TCP中135、139、445、593、1025 等端口的操作方法 (转)(记录下)
操作要领:封闭端口,杜绝网络病毒对这些端口的访问权,以保障计算机安全,减少病毒对上网速度的影响. 近日发现有些人感染了新的网络蠕虫病毒,该病毒使用冲击波病毒专杀工具无法杀除,请各位尽快升级计算机上的杀 ...
- 获取当前网页的的url
如果测试的url地址是http://www.test.com/testweb/default.aspx, 结果如下: Request.ApplicationPath: / ...
- jquery遍历之children()与find()的区别
hildren(selector) 方法是返回匹配元素集合中每个元素的所有子元素(仅儿子辈).参数可选,添加参数表示通过选择器进行过滤,对元素进行筛选. .find(selector)方法是返回匹配元 ...
- 【Leetcode】【hard】Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...