zoukankan      html  css  js  c++  java
  • C#返回数组对象

    //返回数组对象

    public List<User> GetUser()

            {
                try
                {
                    using (SqlConnection testConnection = new SqlConnection(ConnStr.connectionString))
                    {
                        SqlCommand testCommand = testConnection.CreateCommand();

                        testCommand.CommandText = "select [id],[name] from [user]";
                        
                        testConnection.Open();

                     
                        List<User> users = new List<User>();
                        SqlDataReader rd = testCommand.ExecuteReader();

                        while (rd.Read())//read next
                        {
                            User userback = new User();
                            userback.ID = rd.GetInt32(0);
                            userback.Name = rd.GetString(1);
                            users.Add(userback);    //add to list                    
                        }
                        
                        Console.WriteLine("Back all sql User");
                        return  users;
                    }
                }
                catch (Exception e1)
                {
                    Console.WriteLine(e1.Message);
                    return null;
                }

            }
  • 相关阅读:
    用Apache 里面的ab做一个简单的压力测试
    优化加载jQuery的方法
    html的head里出现了 http://c.cnzz.com/core.php
    使用wget命令时发生错误
    Thinkphp 用PHPExcel 导入Excel
    001--初探ts
    006--面试之异步
    001--Node.js之EventLoop
    005--面试原型之jQuery和zepto的简单使用
    004--面试之ES6其他常用的功能
  • 原文地址:https://www.cnblogs.com/no7dw/p/1711306.html
Copyright © 2011-2022 走看看