zoukankan      html  css  js  c++  java
  • SQL存储过程使用方法

    public void findflight()
    
    {
    
    // 创建参数
    
    IDataParameter[] parameters = {
    
    new SqlParameter("@Id", SqlDbType.Int,4) ,
    
    new SqlParameter("@Name", SqlDbType.NVarChar) ,
    
    };
    
    // 设置参数类型
    
    parameters[0].Direction = ParameterDirection.Output; // 设置为输出参数
    
    parameters[1].Value = "张三";

    LoadDate(“P_FindFlihgt”,parameters);
    int id = (int)parameter[0].Value;
    }
    //调用存储过程返回DateTable
     public static DataTable LoadData(string strProcName, params object[] paraValues)
             {
                 DataTable dt = new DataTable();
                 string strConn = ConfigurationManager.ConnectionStrings["HealthHospInfection"].ConnectionString;
                 using (SqlConnection conn = new SqlConnection(strConn))
                 {
                     try
                     {
                        SqlCommand cmd = new SqlCommand();
                         cmd.CommandText = strProcName;
                         // 设置CommandType的类型
                         cmd.CommandType = CommandType.StoredProcedure;
                         cmd.Connection = conn;
                         conn.Open();
     
                         if (paraValues != null)
                         {
                             //添加参数
                             cmd.Parameters.AddRange(paraValues);
                         }
     
                         // 取数据
                         using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
                         {
                             adapter.Fill(dt);
                         }
                     }
                     catch (Exception ex)
                    {
                         MessageBox.Show("错误:" + ex.Message + "/r/n跟踪:" + ex.StackTrace);
                     }
                     finally
                     {
                         conn.Close();
                     }
                 }
                 return dt;
             }      
  • 相关阅读:
    PHP的后期静态绑定
    php的clone 浅拷贝
    python 从文件导入分类
    Yii2 主从 数据库
    什么是 jsonp ?
    为speedphp最新版添加 仿Yii 的简易版 数据验证 支持不同场景,自定义回调
    redis入门指南-安装redis
    composer -vvv
    依赖注入
    yii2-user
  • 原文地址:https://www.cnblogs.com/lcidy/p/8963314.html
Copyright © 2011-2022 走看看