private void BtnSearch_Click(object sender, EventArgs e) { int ro_roomno = Int32.Parse(tbRoomNo.Text); var conn = Database.ConnectDB(); conn.Open(); string query = string.Format("select * from Rooms where RoomNo={0}", ro_roomno); SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader reader = cmd.ExecuteReader(); Room1 ro = new Room1(); while (reader.Read()) { ro.CustomerName = reader.GetString(reader.GetOrdinal("CustomerName")); ro.RoomType = reader.GetString(reader.GetOrdinal("RoomType")); ro.Floor = reader.GetString(reader.GetOrdinal("Floor")); ro.RoomNo = reader.GetInt32(reader.GetOrdinal("RoomNo")); } tbCName.Text = ro.CustomerName; tbRoomType.Text = ro.RoomType; tbFloorNo.Text = ro.Floor; }
private List<Room1>GetRooms() { var conn = Database.ConnectDB(); conn.Open(); string query = "select * from Rooms"; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader reader = cmd.ExecuteReader(); //ArrayList list = new ArrayList(); List<Room1> list = new List<Room1>(); while (reader.Read()) { Room1 r = new Room1(); r.RoomNo = reader.GetInt32(reader.GetOrdinal("RoomNo")); r.CustomerName = reader.GetString(reader.GetOrdinal("CustomerName")); r.RoomType = reader.GetString(reader.GetOrdinal("RoomType")); r.Floor = reader.GetString(reader.GetOrdinal("Floor")); list.Add(r); } return list; }