예제 #1
0
        public List <TUsers> GetUsers()
        {
            SqlDataReader result;
            List <TUsers> users = new List <TUsers>();

            //string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
            string constr = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='|DataDirectory|\PedroMayo.mdf';Integrated Security=True";

            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT IdUser, Name FROM dbo.TUsers"))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection  = con;
                    con.Open();

                    result = cmd.ExecuteReader();

                    users = DataRecordHelper.ConvertTo <TUsers>(result);

                    con.Close();
                }
            }



            //IDataReader

            //return result.AutoMap<>.ToList();
            return(users);
        }