Esempio n. 1
0
        private List <Users1> GetUsers()
        {
            var conn = Database.ConnectDB();

            conn.Open();
            string        query  = "select * from Users";
            SqlCommand    cmd    = new SqlCommand(query, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            //ArrayList list = new ArrayList();
            List <Users1> list = new List <Users1>();

            while (reader.Read())
            {
                Users1 u = new Users1();
                u.UserId    = reader.GetInt32(reader.GetOrdinal("UserId"));
                u.Name      = reader.GetString(reader.GetOrdinal("Name"));
                u.Username  = reader.GetString(reader.GetOrdinal("Username"));
                u.Password  = reader.GetString(reader.GetOrdinal("Password"));
                u.ContactNo = reader.GetString(reader.GetOrdinal("ContactNo"));
                u.Address   = reader.GetString(reader.GetOrdinal("Address"));


                list.Add(u);
            }
            return(list);
        }
Esempio n. 2
0
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            int u_id = Int32.Parse(tbUserid.Text);
            var conn = Database.ConnectDB();

            conn.Open();
            string        query  = string.Format("select * from Users where UserId={0}", u_id);
            SqlCommand    cmd    = new SqlCommand(query, conn);
            SqlDataReader reader = cmd.ExecuteReader();
            Users1        u      = new Users1();

            while (reader.Read())
            {
                u.Name      = reader.GetString(reader.GetOrdinal("Name"));
                u.Username  = reader.GetString(reader.GetOrdinal("Username"));
                u.Password  = reader.GetString(reader.GetOrdinal("Password"));
                u.ContactNo = reader.GetString(reader.GetOrdinal("ContactNo"));
                u.Address   = reader.GetString(reader.GetOrdinal("Address"));
                u.UserId    = reader.GetInt32(reader.GetOrdinal("UserId"));
            }
            tbName.Text      = u.Name;
            tbUsername.Text  = u.Username;
            tbPassword.Text  = u.Password;
            tbContactno.Text = u.ContactNo;
            tbAddress.Text   = u.Address;
        }