zoukankan      html  css  js  c++  java
  • 存储过程系列之存储过程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();

  • 相关阅读:
    1_Maven
    9_项目实战MyShop
    8_文件上传与下载
    使用 selenium 模拟登陆微信公众号平台并且抓取数据
    scrapy框架+scrapy_redis组件的分布式爬虫:爬取某小说网站的所有小说!
    scrapy框架 + redis数据库增量式爬虫 :爬取某小说网站里面的所有小说!
    scrapy框架+redis增量式爬虫: 二进制数据下载>下载某短视频网站里面的短视频的项目工程!
    scrapy框架+redis增量式爬虫: 抓取某短视频里面发布的视频的观看次数、点赞等信息的项目工程!
    在scrapy框架中使用免费的代理ip,解决ip被封禁的问题!!!
    在scrapy框架中使用selenium爬取强国论坛的新闻标题内容+redis增量式
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/5514110.html
Copyright © 2011-2022 走看看