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;
                }

            }
  • 相关阅读:
    Linux下链接mysql数据库的命令
    linux cp命令参数及用法详解
    svn命令在linux下的使用
    把一个一维数组转换为in ()
    JS修改标签中的文本且不影响其中标签
    Underscore template
    JavaScript动态加载js文件
    JavaScript库基本格式写法
    JavaScript class 使用
    Uncaught TypeError: Cannot read property 'ownerDocument' of null
  • 原文地址:https://www.cnblogs.com/no7dw/p/1711306.html
Copyright © 2011-2022 走看看