存储过程系列之存储过程sql数据库调用和程序代码调用
1、存储过程,无参数的存储过程
创建无参数存储存储过程
Create Procedure DCEMREMR_TEMPLATE
As
SELECT TOP 10 [FILENAME],[FILETITLE],[FILECONTENT] from [DCEMR].[dbo].[EMR_TEMPLATE];
调用无参数存储存储过程
sql 数据库中的额调用 exec DCEMREMR_TEMPLATE;
sql程序代码调用
//无参数存储过程
string connecting = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=DCEMR";
SqlConnection theConnect = new SqlConnection(connecting);
theConnect.Open();
SqlCommand theCommand = theConnect.CreateCommand();
theCommand.CommandText = "DCEMREMR_TEMPLATE";
theCommand.CommandType = CommandType.StoredProcedure;
SqlDataReader theReader = theCommand.ExecuteReader();
while (theReader.Read())
{
string xx = theReader.GetString(0).ToString();
}
theConnect.Close();
2、有参数存储过程,无返回值
创建有参数存储存储过程,无返回值
Go
Create Procedure DCEMREMRTEMPLATE100
@filename nvarchar(500)
As
SELECT [FILENAME],[FILETITLE],[FILECONTENT] from [DCEMR].[dbo].[EMR_TEMPLATE] where [FILEname]=@filename;
调用有参数存储过程,无返回值
sql 数据库中的额调用 exec DCEMREMRTEMPLATE100 ‘新建目录’;
sql程序代码调用
//有参数存储过程,无返回值
string connecting = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=DCEMR";
SqlConnection theConnect = new SqlConnection(connecting);
theConnect.Open();
SqlCommand theCommand = theConnect.CreateCommand();
theCommand.CommandText = "DCEMREMRTEMPLATE101";
theCommand.CommandType = CommandType.StoredProcedure;
theCommand.Parameters.Add("@filename",SqlDbType.NVarChar);
theCommand.Parameters["@filename"].Value = "新建目录";
SqlDataReader theReader = theCommand.ExecuteReader();
while (theReader.Read())
{
string xx = theReader.GetString(0).ToString();
}
theConnect.Close();
3、有参数存储过程,有返回值(参数@filename,返回参数@Rowcount)
创建有参数存储过程,有返回值
Go
Create Procedure DCEMREMRTEMPLATE101
@filename nvarchar(500),
@Rowcount int output
As
SELECT [FILENAME],[FILETITLE],[FILECONTENT] from [DCEMR].[dbo].[EMR_TEMPLATE] where [FILEname]=@filename
set @Rowcount=@Rowcount;
调用参数存储存储过程,有返回值
sql 数据库中的额调用 exec DCEMREMRTEMPLATE101 ‘新建目录’,2;
sql程序代码调用
//有参数存储过程
string connecting = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=DCEMR";
SqlConnection theConnect = new SqlConnection(connecting);
theConnect.Open();
SqlCommand theCommand = theConnect.CreateCommand();
theCommand.CommandText = "DCEMREMRTEMPLATE101";
theCommand.CommandType = CommandType.StoredProcedure;
theCommand.Parameters.Add("@filename",SqlDbType.NVarChar);
theCommand.Parameters["@filename"].Value = "新建目录";
theCommand.Parameters.Add("@Rowcount", SqlDbType.Int);
theCommand.Parameters["@Rowcount"].Direction = ParameterDirection.Output;
//theCommand.Parameters["@Rowcount"].Value = 2;
//theCommand.ExecuteNonQuery();
object ss = theCommand.ExecuteScalar();
//MessageBox.Show( theCommand.Parameters["@Rowcount"].Value.ToString());
SqlDataReader theReader = theCommand.ExecuteReader();
while (theReader.Read())
{
string xx = theReader.GetString(0).ToString();
}
theConnect.Close();
相关文章
- 数据库-进阶-存储引擎
- 数据库/存储学习路径推荐
- SQL开发知识:Sql中存储过程的定义、修改和删除操作
- Linux下将SQL文件导入数据库的命令指南(linux导入sql文件命令)
- 改善MySQL存储引擎:提高数据库性能(修改mysql存储引擎)
- SQL与MySQL:开放式数据库创新(sql和mysql)
- 极速上手:使用SQL访问Oracle数据库(sql访问oracle数据库)
- Oracle数据库登录存储过程及使用指南(oracle登录存储过程)
- 提升效率必看:MySQL数据库存储优化技巧(mysql数据库存储优化)
- 实现Oracle数据库乘法操作的SQL语句(oracle乘法sql)
- 使用 MySQL 外键优化 SQL 数据库设计(mysql外键sql)
- 数据库利用SQL文件建立MSSQL数据库的步骤(sql文件建立mssql)
- MySQL安全策略:确保数据库存储和访问的完整性与保密性(mysql安全策略)
- 如何使用 MySQL 还原 SQL 数据库备份文件?(mysql还原sql)
- SQL玩转MySQL,数据库操作简单易学(mysql中使用sql)
- 登录Oracle数据库探索存储在云里的数据之谜(login oracle)
- ATM存储Oracle数据库实现自动化提取(ATM存储oracle)
- 千亿量级数据库MySQL储存实践(10亿数据mysql存储)
- MySQL是用来管理和存储数据的一种关系型数据库管理系统它可以用于Web开发应用程序和企业级数据库
- Redis放弃传统数据库,体验新的弹性存储(先写redis 还是写库)
- Oracle数据库中的安全数据存储策略(oracle中数据存储)
- Oracle SQL提交轻松实现数据库信息更新(oracle sql提交)
- Oracle 64位SQL助力数据库优化管理(oracle64位sql)