zoukankan      html  css  js  c++  java
  • ado.net 执行sql存储过程

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    
    public partial class Main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
            int totalpage;
            List<StuInfo> List = new List<StuInfo>();
            gv_stu.DataSource = GetStuInfo(10, 2, ' ', out totalpage);
            gv_stu.DataBind();
        }
        public List<StuInfo> GetStuInfo(int pagesize,int currentpage,string condition,out int totalpage)
        {
            List<StuInfo> List = new List<StuInfo>();
            //string sqlconstr = "Data Source=.;Initial Catalog=Example;User ID=sa;Password=123456";
            string sqlconstr = "Data Source=.;Initial Catalog=Example;Integrated Security=true";
            string sql = "proc_GetStuInfo";
            SqlConnection con = new SqlConnection(sqlconstr);
            SqlCommand cmd = new SqlCommand(sql, con);
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            SqlParameter[] para = {
                                      new SqlParameter("@pagesize",pagesize),
                                      new SqlParameter("@currentpage",currentpage),
                                      new SqlParameter("@condition",condition),
                                      new SqlParameter("@pagesize",SqlDbType.Int)
                                  };
            para[3].Direction = ParameterDirection.Output;
            cmd.Parameters.AddRange(para);
            {
                while(sdr.Read())
                {
                    StuInfo stu = new StuInfo();
                    stu.Stuid = sdr["stuid"].ToString();
                    stu.Stuname = sdr["stuname"].ToString();
                    stu.Age = Convert.ToInt32(sdr["age"]);
                    stu.Address = sdr["address"].ToString();
                    List.Add(stu);
                }
            }
            con.Close();
            totalpage =Convert.ToInt32(para[3].Value);
            return List;
        }
    }
  • 相关阅读:
    Unable to load native-hadoop library for your platform... using builtin-java classes where applica
    Hadoop通过url地址访问HDFS
    Hadoop通过url地址访问HDFS
    Hadoop通过API访问HDFS
    Hadoop通过API访问HDFS
    maven项目测试HDFS读取文件
    maven项目测试HDFS读取文件
    查看镜像文件
    2.决定你是穷人还是富人的12条
    2.row_number() over (partition by col1 order by col2)的用法
  • 原文地址:https://www.cnblogs.com/cylblogs/p/4944010.html
Copyright © 2011-2022 走看看