• Ado调用存储过程


      public ReturnModel GetStudent(string json)
            {
                ParamsModel model = JsonConvert.DeserializeObject<ParamsModel>(json);
    
                //连接对象
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["StudentConn"].ToString()))
                {
                    //命令对象
                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandType = CommandType.StoredProcedure;//存储过程类型
                    cmd.CommandText = "proc_Page";//存储过程名称
                    //参数  ParameterName参数名字   SqlDbType参数类型   SqlValue参数值  Direction参数描述(输出、输入)
                    SqlParameter[] sqls = new SqlParameter[] {
                        new SqlParameter{ ParameterName="BigScore", SqlDbType=SqlDbType.Int,SqlValue=model.BigScore },
                        new SqlParameter{ ParameterName="CID", SqlDbType=SqlDbType.Int,SqlValue=model.CID },
                        new SqlParameter{ ParameterName="ClaId", SqlDbType=SqlDbType.Int,SqlValue=model.ClaId },
                        new SqlParameter{ ParameterName="order", SqlDbType=SqlDbType.Int,SqlValue=model.order },
                        new SqlParameter{ ParameterName="PageIndex", SqlDbType=SqlDbType.Int,SqlValue=model.PageIndex },
                        new SqlParameter{ ParameterName="PageSize", SqlDbType=SqlDbType.Int,SqlValue=model.PageSize },
                        new SqlParameter{ ParameterName="Sage", SqlDbType=SqlDbType.VarChar,SqlValue=model.Sage },
                        new SqlParameter{ ParameterName="SmallScore", SqlDbType=SqlDbType.Int,SqlValue=model.SmallScore },
                        new SqlParameter{ ParameterName="Sname", SqlDbType=SqlDbType.VarChar,Size=20,SqlValue=model.Sname },
                        new SqlParameter{ ParameterName="Tname", SqlDbType=SqlDbType.VarChar,Size=20,SqlValue=model.Tname },
                        new SqlParameter{ ParameterName="TotalCount", SqlDbType=SqlDbType.Int, Direction=ParameterDirection.Output},
                    };
                    cmd.Parameters.AddRange(sqls);
                    //适配器
                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    DataTable dt = new DataTable("Student");
                    sda.Fill(dt);
                    //总条数
                    int totalCount = Convert.ToInt32(cmd.Parameters["TotalCount"].Value);
    
                    ReturnModel returnModel = new ReturnModel
                    {
                        Dt = dt,
                        TotalCount= totalCount
                    };
                  return returnModel;
                }
            }
  • 相关阅读:
    java——阶段性整理(方法的重载重写和一些关键字)
    设计模式——单例模式
    source
    set和setenv
    c++编译加执行脚本
    python脚本小记
    转义字符
    istream_iterator/ostream_iterator
    字符串替换程序 p324
    程序编译后运行时的内存分配
  • 原文地址:https://www.cnblogs.com/ly-03-04/p/12324699.html
Copyright © 2020-2023  润新知