C# 调用SQL的存储过程的接口及实现
1. 接口为ExecuteStoredProcedure(string storedProcedureName, params ObjectParameter[] parameters)
2. 参数为存储过程名字, 及输入值。
3. 思路:创建连接(连接中指定了是Sql/MySql/ODBC等等); 创建通用DbCommand;更改Text以及Type;添加通用Parameter(DBParameter是抽象类,因此需要判断connection类型);判断连接状态(需Open); 调用Execute方法; 关闭连接。
4.
实现如下:
// In V1 of the EF, the context connection is always an EntityConnection EntityConnection entityConnection = (EntityConnection)protocolDB.Connection; // The EntityConnection exposes the underlying store connection DbConnection storeConnection = entityConnection.StoreConnection; DbCommand command = storeConnection.CreateCommand(); command.CommandText = storedProcedureName; command.CommandType = CommandType.StoredProcedure; if (storeConnection is SqlConnection) { foreach (ObjectParameter p in parameters) { command.Parameters.Add(new SqlParameter { ParameterName = p.Name, Value = p.Value }); } } else if (storeConnection is MySqlConnection) { foreach (ObjectParameter p in parameters) { command.Parameters.Add(new MySqlParameter { ParameterName = p.Name, Value = p.Value }); } } else { return enProtocolDBReturnCodes.OPERATION_FAILED; } bool openingConnection = command.Connection.State == ConnectionState.Closed; if (openingConnection) { command.Connection.Open(); } command.ExecuteNonQuery(); if (openingConnection && command.Connection.State == ConnectionState.Open) { command.Connection.Close(); }
转载于:https://blog.51cto.com/muzizongheng/1333047
C# 调用SQL的存储过程的接口及实现相关推荐
- 不是操作系统的是JAVA_在Jdbc中可以调用数据库的存储过程的接口是( )。
[多选题]下面属于AWT事件的高级事件的是(). [其它]1.1000字的故事梗概.是整个电视剧的总体梗概. 2.列出每条情节线的事件 3.核心人物的人物小传,每个人物500字 4.以Word附件的形 ...
- java调用存储过程 sql server_Java中调用SQL Server存储过程示例
Java中调用SQL Server存储过程示例2007-09-03 08:48来源:论坛整理作者:孟子E章责任编辑:方舟·yesky评论(3) 最近做了个Java的小项目(第一次写Java的项目哦), ...
- ASP调用sql server 存储过程详解-附带实例-
ado文档对使用指定属性创建新的 Parameter 对象. 语法 Set parameter = command.CreateParameter (Name, Type, Direction, Si ...
- Java/JSP中调用SQL Server存储过程完整示例收藏
最近做了个Java的小项目(第一次写Java的项目哦), 到网上搜索了半天,找到了一个比较好点的调用存储过程的例子,而且网上普遍采用的都是setXXX((int parameterIndex, XXX ...
- server使用abp中调用存储过程 sql_ASP调用sql server 存储过程详解-附带实例-
ado文档对使用指定属性创建新的 Parameter 对象. 语法 Set parameter = command.CreateParameter (Name, Type, Direction, Si ...
- c# 调用SQL Server存储过程返回值(转)
--用ParameterDirection.ReturnValue; 返回值 CREATE PROCEDURE dbo.a AS declare @i intselect @i=count(*) ...
- SQL server 存储过程的建立和调用
SQL server 存储过程的建立和调用 存储过程的建立和调用 --1.1准备测试需要的数据库:test,数据表:物料表,采购表 if not exists (select * from maste ...
- 第七节:EF Core调用SQL语句和存储过程
一. 查询类(FromSql) 1.说明 A. SQL查询必须返回实体的所有属性字段. B. 结果集中的列名必须与属性映射到的列名相匹配. C. SQL查询不能包含关联数据 D. 除Select以为的 ...
- C#调用SQL中的存储过程中有output参数,存储过程执行过程中返回信息
C#调用SQL中的存储过程中有output参数,类型是字符型的时候一定要指定参数的长度.不然获取到的结果总是只有第一字符.本人就是由于这个原因,折腾了很久.在此记录一下,供大家以后参考! 例如: CR ...
最新文章
- 风控算法干货交流来了!
- Linux7 CENTOS7修改root密码
- 第1期 | IOST开发者激励计划任务更新
- python 用命令安装pip_利用Python的pip命令安装nump
- asp.net发布网站的详细步骤
- I/O复用的 select poll和epoll的简单实现
- 栈应用:中缀表达式转后缀表达式
- 显卡坏,导致机器无法启动
- OpenGL超级宝典(第7版)之第八章基元处理
- java 多态(重写和重载)
- STM32第九课(Input Capture, HAL)
- 车载TBOX,4G北斗/GPS双模定位
- 科目三-上海松江小昆山
- matlab由离散点绘制光滑曲线并额外标注点
- 【密码学】HMAC与HS256算法
- 小心肝队-冲刺日志(第六天)
- 高效能技术领导者,不仅是首席技术官,更是首席情绪官
- 习题6_5 巡逻机器人(Patrol Robot, ACM/ICPC Hanoi 2006, UVa1600)
- 在Linux系统搭建DNS服务器
- 直流电机控制与TB6612FNG驱动芯片