❔ Filling a combo box in a class that is from a form
So I have a project that requires me to use databases, I chose to use access database since I am familiar with it. But i am trying to put in some combo boxes with the data from the database. When I did that it worked, but my teacher asked me to put it in the same class that I read my data from. Is this possible?
29 Replies
so this is the code I used to get the data from the database into the combo box and my teacher asked to do it in clsData (the class i am using to read data from the database to then use for things like my login page)
that would be a good idea
one more layer could be even a better idea
what do you mean with one more layer?
just start with ui and repository, then we'll see if other improvements are required
being honest i don't really understand what you mean. Do you mean like improving the ui?
so, ui would be you form and controls
repository would be the class that reads and writes data from the table
this makes sense?
yes, make the form and controls then the class and then improve them both
you will also need another class for the data returned by the repository
you could think of making some folders in your solution
Being honest never made a folder before in my solution
if you have like 1 or 2 files who cares, but when you start having a bunch of files that works on different stuff one from another you could start thinking about it
oh oke 👍
So i made a folder with all my classes, but i dont know if i could do it better. So i have a class that does the calculations of how much insuline the user must use (program is for people with diabetes) and then i have a class for getting the things out of the database and then i have a class that contains all the info so it can be used globally
So all of my forms are connected to the clsData (database class) and one of them is connected to clsBerekeningen (aka the class that does the calculations)
and i also wanted to add a query that updates the product from the access database and the code does not work
that's the code i use to update the data
geg. is the information class i use to get global variables
do you have a naming convention? if clsData deals with tblProduct, probably it could named ProductTable or ProductRepository
same goes for clsBerekeningen, to know what it is at first sight, it could be for example InsulineCalculator or something
does not work means that nothing happens?
well for example this is wrong
"WHERE" + geg.Productnaam + " = @productNaam";
first because there is no space after WHERE
then because geg.Productnaam is the value, not the field name?
and the same is for all other fields, you shouldn't be using geg into the query if you are passing it in the command.Parameters
so it would be something like
i don't know the fields names but kind of like this
also, is there not a ProductId, instead of searching for name?Its both things so i got tblProducts and tblLogin both coming from clsDate
clsData*
There is
i bet they are used in entirely different places, one is for authentication and one is the products, so maybe they could be splitted in two diffrent classes
they are used in different places indeed, just in one form they both used (for the main form where i will have a tabcontrol with the products etc where they can select, edet products but also see their profile)
the clsBerekeningen is used for multiple calculations and its a requirement to have a class this was my first thought on putting something in a class
for the combo box?
yes but also in general, for using stuff that you get/put int a table
by requirement you mean having one class with all the methods to calculate stuff in it?
sort of yes, so our main requirements where
have a extern database for full points, intern would be -15 points, a text file would be -25 points no database is 0 points
we needed atleast one class
so you can have more classes
Yes
Just minimum 1 if we don't have any then 0 points on that
the practice is to organize code that works on the same stuff in a class
or eventually same namespace
Oke 🙂
My teacher told me also that i needed to do some stuff on the naming labels and stuff like making code efficient
that would be a good thing to do
the basis of it is essentially how do you explain your intentions in your code
So what it does?
what it does in the sense of what it does in the application
Ooo
hey dont, i got a file with all the requierments of what the projects needs to have.
and what about it
If you want i can send them 🙂
wouldn't it be better if they were available here for everyone?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.