Welcome back.
So let's go ahead and create a new folder.
And as you can see, I cannot do that because my program is running.
So let me stop that and go to the Solution Explorer, right click here and add a new folder.
And I'm going to call this folder data base.
And inside of this database, we need to create a new item.
So add new item.
And here I'm going to use data.
So select data here and then service based database, and then you can give it a name and I'm going
to give it the name of currency converter.
You could of course call it currency converter data.
I'm just going to call it currency converter here.
Okay, now we have this MDF file.
This currency converter MDF file.
And once you double click on it, you can see here on the left hand side, the server explorer opens
up and you see we have data connections here with tables.
Even though there are none views, there are none functions and so forth.
So basically we only have assemblies here, but what we want to have is tables.
So we actually want to have a table.
So let's right click on tables and add a new table.
So then this new window will come up.
DBO dot table design in which you now can design a table.
So you can do it directly.
Here at the top, you can say, okay, I want to have multiple columns and as you can see, the ID column
is automatically there.
So these are, by the way, your columns and you can define of what type the columns should be.
So you can.
As I said at the manually.
But the easier way would be if you do it via code.
So here at the bottom we're using SQL code.
So we say create a table DB table with an ID.
Which is of type one with a column called ID, which is of type int, which cannot be null and which
is our primary key.
So what is a primary key?
A primary key is something that is unique.
So you need to have one primary key in your table, otherwise you would have a complete mess.
Okay.
And the primary key basically allows you to identify every single unique row.
For example, if you have a database with 10 million people, okay, then there is a high chance that
you will have two John Smiths in there.
And if they don't have something that makes them unique, then you could mix them up and suddenly if
you send one of them to jail, well, by accident you could send a notice to the wrong guy and the wrong
guy would go to jail.
Let's say the other guy wins in the lottery.
And for for example, you send out the notification about him winning the lottery.
Well, then the wrong John Smith could win the lottery.
And that's why you have uniquely identifiable values.
For example, the Social Security number is unique for every single person, but in a database that
would be the ID, So the identification value and it is the primary key, so to speak, because this
one is unique.
So every single row has a new.
ID or different ID, So it starts with zero, then it's one, then it's two.
So it cannot be that two rows have the same ID, They will always have different types of IDs.
That is taken care of by our program because we say that the ID is our primary key, so it will increment
it with every single new entry and it will give it a new ID automatically.
Okay.
So I'm going to.
Use this.
Slightly more advanced code, as you can see here.
So I'm creating a table which I call currency Master.
So I'm not going to call this table table.
I'm just going to call this table currency underscore master.
And I have an ID which is of type INT, which is the identifier, which is the identity, and it's not
null.
Okay.
Allows null.
You can see here is this column.
It's set to false so it's not possible to make this a null.
It has to have a value.
Null means it's empty.
Okay, so the ID may not be empty even though we, for example, don't have an amount entered and the
currency name entered, it will already have an ID then for the float value or for the amount.
I say that the amount should be of type float and it can be null, so it can be empty for the column
currency name.
I want to use something called nvarchar, which is basically just saying I want to be able to enter
a value of up to 50 characters of up to 50 variable characters.
Okay, so there are different types or data types that you can use.
You can find integer in here, float and char and text.
So a bunch of different kinds of data types.
And if you want to know more about the data types, you can of course check out the documentation on
it.
You can see that there are a bunch you could just really enter any of them and read in depth what they
are about.
So for example, tiny INT would be a very small integer with little size range.
So if you want to store very small data you would or very small numbers you would use tiny int for example.
Or if you just want to use a very small text, you could use an VarChar, not 50, but what do we have
here?
Well, we have Max here, for example.
But you could use something.
VarChar Well, as it seems, it doesn't offer me a small one, but there are different options that
you have here.
Okay.
When it comes to your data type.
So in a database, you could use a store, something like date time.
You can use decimals, floats, even store full images in here.
So there is this data type image in there as well.
And yeah, that's basically it.
Okay, so we are using Nvarchar, which is like a string.
You could say this is a string.
So I want to store the currency name as a string or as a text, but it's limited to 50 characters.
And then the primary key is clustered and it is the ID that we're using, which is ASC, which stands
for Ascending.
So with every single new entry, it will increase by one.
So it starts with one and it goes up by one.
This is what I defined here.
So this is the seat and this is the increment.
So I say it should increment by one for every single new entry.
So the first entry will be one.
The second entry will be two, the third entry will be three and so forth.
And by the way, SQL is basically SQL code that you can execute here.
So this is SQL code.
So I'm creating this table, right, with all of these properties.
And here at the top hand side, you can see how this table is going to look like.
So it basically helps us in a visual way.
These are going to be the different columns that you will have in your database and you can then click
update.
And.
Update the database and then it will update your database for you.
Now, if you look at your server Explorer and you refresh it now, you will see that now you have your
currency master.
Okay.
Your currency master has an ID, an amount, and a currency name.
So these are the columns that you now have in your database called Currency Underscore master.
And now we can access this currency master and we can fill it with data, which is what we wanted.
But in order for this to work, we first of all need to make sure that we have a connection string and
therefore we need to go to our app dot config file and I'm going to add it.
Inside of my configuration.
Underneath my startup.
So here I will create a new connection string.
So inside of connection strings, I'm going to say I want to have a new connection string.
So I'm adding a new connection.
String with the name of Connection.
String.
And the connection string property.
That is where you need to enter something quite long.
And I'm just going to do it.
Real quick and go through what's actually happening here.
Okay, so this is my connection string.
Okay.
And my connection String.
Says data source equals local DB because we are using a database which is installed locally and it's
a Microsoft SQL Local database, and the attached database file name is well, the physical file is
equal to and this is the path where my file is.
Okay, so the path goes all the way up to here.
So basically in your.
Solution explorer if you go to your database.
This MDF file.
You want to get its path.
So copy full path and then you can use it and replace your own path with the path that I had here.
So in my case it's under C users.
Dennis Source Repos, Currency converter, static currency converter.
Static is the name of the project, right?
And then inside of that, I have once again this folder currency converter static.
Then I have this database folder and then inside of that database folder I have this file called currency
Converter MDF, which is this file here.
So however you called your file, that's going to be basically the Or wherever you stored it and however
you called it, that's going to be this location that you have here.
And then it's integrated and the security is set to true.
Okay.
So these are the basic settings that I have here.
Provider name is SQL Server in my case, that's set to it.
If you want to know more about any of the properties, as I said, always check out the documentation
if you want to really understand in depth.
But I think if I go in depth about everything, this will you will not find an ending.
So basically that is how you can now set up your database.
Okay.
And it's important that your app config is saved, your main window Xaml is saved as well.
Your database is ready.
You have made sure that you clicked update that it is available here in your tables.
You can refresh it if you want to make sure that it's really there.
But now basically this currency MDF file and if you look at the properties, you will find the full
path here as well.
So now you basically have your database set up, it's ready and you can use it in your code now, which
is what we're going to do now.