Welcome back.
Now that you know how to create a zoo table and associated animals table, it's time for you to create
this table here, which is our animals table.
So it's going to be all the animals that there are in our database that should be displayed here.
So we have an animal table, and I want you to display all of its data in this list box here.
So please go ahead and try that.
It shouldn't be too difficult.
You can pretty much apply what you have seen in the last two videos, so please go ahead and try that.
All right.
I hope you did.
And we are not adding the animal to zoo and kind of stuff, all these buttons.
We're not going to add that now, but we're just going to add this little additional list box there.
And I'm just going to do it like that, actually.
Just gonna copy this list box here, copy paste, drag it over so that I have roughly the same distance
between the two.
And now I'm going to make it a little longer.
Maybe like that.
And later on, I'm going to add a button here.
As you can see, the well, the numbers don't fit perfectly, but that's something that we can apply
later on.
Once we have all the different elements in here, we can change the window size and those kind of things.
All right.
And I'm not going to add a label yet because I'm going to add a button later on, which is just going
to have the add button or add animal button and the delete animal button.
All right.
So now we have this list box.
I'm going to go to this method.
And let's go to our show Zoo Methods and well, we can pretty much just copy that or well, actually,
let's build it ourselves.
Right?
So let's create a new method for that and I'm going to go ahead and call that private void, show all
animals.
And now, once again, what do we need?
First of all, we need a string, which is our query, where we just want to select all animals.
So select all from animal just like that.
And now in order to run the query, we need an SQL data adapter.
I'm going to call it a SQL data adapter, which is a new SQL data adapter.
And in there we need to hand over a query that we want to run, which we created here, and a connection
which we have set up here, this SQL connection.
And as you can see, we initialize it here in our main window, initialize or constructor, and I'm
going to add the query here, query and the SQL Connection.
And now we can use that adapter.
And the advantage of the adapter, as I said, is that you don't need to open and close the SQL connection
manually because we're going to do that later on.
You will see how to do that and you will now see the, let's say, nicer way of having an adapter.
But sometimes it's just useful to still have this SQL connection open and closed and do things manually
in there.
So I'm going to hand over the SQL data adapter and within those curly brackets, I want to display my
stuff onto the list that we have.
So in order to get that, we need, first of all, all the data from the table, which is going to be
a data table and I'm going to call it animal table, which is a new data table.
So I'm going to initialize it straight away.
And then we need to go ahead and fill our SQL adapter or data adapter with this animal table or actually
the other way around.
So this animal table gets our SQL data adapter information, which runs the query onto our database.
So that's what this field method will do.
And now that we have done that.
Actually here it's the small SE, not the Capital One.
Now we need to apply all of that to our list.
So we have a list, associated animals and we have a list with our zoos, but we do not have a list
with all animals yet.
Well, we do, but we have not given the name to it yet.
And as you can see, it's called List Associated Animals Copy, because I just copied and pasted it
and then created this for me automatically.
So I'm going to name it a list, all animals.
So it's the list of all animals.
And once that is done, I can go back to my CSS class.
So my code behind and in here I'm going to call my list, all animals list and I need to display the
member path.
So get subsets of path to value on the source object.
So I need to do that and that will be the name because I want to have the name of my animal right next.
I need to apply the selected value path.
So list all animals.
Selected Value Path is going to be the ID.
So pretty much the first value is 1/2 values too and so forth.
So all those IDs that needs to fill all of them and list all animals that item source.
So where do we get the information from?
Well, we'll get it from our animal table default view property.
So it gets a view of the table that may include a filtered view or a cursor position.
That's exactly what we need.
And this can go well, but it also can go wrong.
So we need to have a tri catch block around it.
So I'm just going to create a try catch block with double tap and instead of throwing the error, I'm
just going to write something on the message box.
So message box, dot show and this exception, I'm going to call it E and it should show e dot to string.
So I just want to show what the error was if there is an error showing all the animals because anything
could go wrong.
This statement here, the query could be wrong or the connection could be wrong or it couldn't work
for now.
Or the string that we have created here could be incorrect.
The display member path could be incorrect.
All of those things could go wrong because we are using hardcoded string names here and that can turn
into plenty of problems.
And yeah, that's why we need this try and catch.
BLOCK Now that we have that, we can go ahead and show all animals from the start.
So let's just call the show All Animals method here in our constructor Main Window and I'm going to
run it again to actually see more beautiful animals in my list.
So there we are, shark, clownfish, monkey, wolf, gecko, crocodile and so forth.
I hope you manage to do that yourself.
Now you can go ahead and add some more data just to see that this is actually updating.
And in order to do that, you can, of course, do it the old fashioned way by, well, changing the
data straight away in the database here and the data connection.
So yeah, first you need to refresh and connect to it and then you can apply.
It changes to the tables.
So in here, animal show table data.
All right.
So that was it for this video.
We are going to add the buttons in the next video and I'm going to show you how to add things and how
to use all the functionality that is still missing.
So see you in the next video.