How to display records from a database without using DataGridView

Lin100

Well-known member
Joined
Dec 12, 2022
Messages
69
Programming Experience
10+
In Ms Access database, a form can display records from a table or query
in a single record as oppose to multiple records like a DataGridView

I want to display records from an Access database on a C# form without using DataGridView
because there are too many fields. When using DataGridView, you have to scroll left and right if
there are too many fields.

The attachment depict a form that has many fields but with just one record. To see the second
record, or third or fourth, the user just click on the arrow below. I want a C# form to do the same.
How would I do this in C# ?
 

Attachments

  • Reservation Form That Display One Record At A Time.jpg
    Reservation Form That Display One Record At A Time.jpg
    173.2 KB · Views: 57
Thanks Skydiver for the information on how to zip using Windows built-in feature.
Okay, cjard and everyone else. Here is the zip attachment. It is working fine.

1) Please open the project and changed from 4.7.2 to 4.8. When you do, there will
be many of the same errors throughout many files. You can fix this.

2) After you are done with number 1 above, please look at the code, and alter it
so that it will be more efficient and conform to better C# programming practice.

3) In form Reservation3.cs, you can change it and put in the built database
navigation button of Record-Foward, Record-Backward and perhaps
New-Record ?
In form Reservation3.cs, I just want the form to display a single record and
not use DataGridView so I don't have to scroll left and right. Because of this
the form would need navigation button of Record-Foward, Record-Backward.

4) My reason for using the underscore notation is for readability.
My_Account is alot easier to read then MyAccount.

5) Once you are done, please attach the correct zip files so I can look at it.
Feel free to put your own comments on the code such as
// Cjard comment
// Skydiver comment
// jmcilhinney
 
I have removed your attachment because, based on the size, it almost certainly contained compiled binaries. Please attach ONLY the source code. If you're going to upload an entire project/solution, which should always be a last resort, then make sure that you delete the bin and obj folders, which contained the compiled binaries.

If the size was due to something else, e.g. image resources, then I apologise, but experience tells me that it was almost certainly due to binary files.
 
I have removed your attachment because, based on the size, it almost certainly contained compiled binaries. Please attach ONLY the source code. If you're going to upload an entire project/solution, which should always be a last resort, then make sure that you delete the bin and obj folders, which contained the compiled binaries.

If the size was due to something else, e.g. image resources, then I apologise, but experience tells me that it was almost certainly due to binary files.

You must look again. The attachment that I have does not include any files in bin or obj folder. Inside there was a very small 2016 Access database that have 4 small tables and a query. The toal size of that Zip file is 463 Kilobytes, which is very small.
 
Do you still have that zip file ? If not I will upload that same zip file again.
The size of that zip file is 463 Kilobytes, which is very small.
 
We don't need the database. We just want to see the source code.
 
Here is the zip file without any files in bin or obj folder and with no Access database.
 

Attachments

  • Apartment_Management_2ZIPPED.zip
    380.6 KB · Views: 8
Oh.. I was rather hoping for the database actually, because I wanted to knock together a quick video about using the typed dataset designer and data binding..(Sorry to go from pillar to post)
 
Last edited:
My_Account is alot easier to read then MyAccount
Probably not for 99.9999% of C# developers that follow microsoft's conventions. Underscores are seldom used, most commonly only as a leader to identify a class level private field and to avoid use of `this` in e.g. a cosntructor assigning someArgument to _someArgument

"I have my own convention" is fine when noone else will read your code, but then taking unconventional code to other people and asking for them to input on it isn't ideal
 
Oh.. I was rather hoping for the database actually, because I wanted to knock together a quick video
Sorry about that... I thought from the other thread you just wanted to show what the code would look lik using a more modern approach. Was not anticipating you would want to put together a video of working code.
 
Oh.. I was rather hoping for the database actually, because I wanted to knock together a quick video about using the typed dataset designer and data binding..(Sorry to go from pillar to post)

Hi cjard. The attachment has that access database. Moderator, please do not delete it.
 

Attachments

  • AMS_2007.zip
    33 KB · Views: 6
1) Please open the project and changed from 4.7.2 to 4.8. When you do, there will
be many of the same errors throughout many files. You can fix this.
This is not an issue with moving from 4.7.2 to 4.8. This is an issue with the MSDataSetGenerator.

The issue can be reproduced by right clicking on the .XSD in the Project Explorer and then selecting "Run Custom Tool". For some reason this renames your AMS_2007DataSet class to AMS_2007DataSet1 class. Viola! Same build errors without even changing framework versions.

Anyway, the workaround seems to be to update all the WinForms Designer generated code to use the new AMS_2007DataSet1 class name.
 
I don't know. I have never used the strongly typed data sets before.

Double clicking in the .XSD file, the Properties pane on the right updates to show a DataSet Name value with "AMS_2007DataSet1". Changing that value to remove the 1 suffixes does not cause any conflicts, but there is still 2 build errors about AMS_2007DataSet1DataTable now being missing.
 
OK, so some first things first

1673006690908.png


Assuming a property is a building, like a high rise, and a unit is one or more residential units within the building, I probably would have made it so a Unit has a PropertyId (because realistically a unit can only be inside one building) and a UnitId, and I'd have UnitId be unique across all units everywhere - I wouldn't use the door number, such that two different units in two different buildings could have ID 100 because the door number is 100 on both units.

I would not have used property name as a key in other tables - names repeat; there is sure to be more than one building in the world called Beach Villas so you're engineering a collision in there that the poor user will ahve to work around by calling the second property they take on something else, such as repeating the city name into the property name; if I was making something that was relating to the property, such as the street address of the building, then an address record would have a property Id, or perhaps a property would have an address ID - we flip relationships around depending on how it suits us - can a property have multiple addresses? Probably not. Can an address have multiple properties? Maybe - so maybe the Property should have an address ID. The main thing is it's usually quite helpful to have a unique number for a record - it's one column that we can then establish relationships with

On relationships; the tenant and the unit clearly have a relationship when a tenant is leasing a unit, and we might want to keep ahold of that history too, even when the lease is over. One unit has many tenants according to your diagram, and yes, that might be true in the real world, for a house share.. But can one person ever rent two units? That also happens in the real world. Do you make another Tenant record for the same person, so you now have two John Does to keep up to date, that actually refer to the same person? What if one ends up with a good credit risk and the otehr a bad?
If you're having a record for John Doe, a particular human then he should probably have only one record. This would then mean he has e.g. TenantId 123. If youre having a record for apartment 104 (unit id 232323) Beach Villas (property Id 45) then on the question of how John can have multiple units and how a unit can have multiple tenants, you can actually have a third table, TenantUnit that tracks the two IDs as a pair, and then maybe also things like the length of the lease.. So you can record that tenant 123 (john) in unit 232323 from date to date - you only have one tenant record, one unit record, and this other table TenantUnit has multiple records in it that track every lease John has for all the units, and also tracks every tenant apartment 104 has/did have. The TenantId,UnitId in the TenantUnit table is unique, unless one person can lease one unit multiple times (move out and then back in later?) so you then start thinking whether to make the date part of the key, or maybe there is a new tenancy agreement record that is part of the key

Maybe also TenantUnit is the thing that has the reservation - everyone who takes a unit pays a reservation, we track that historically etc..

Think about that relationship thing with single numeric IDs though; you're making property name and unit number a key of Unit, which is understandable, but hard work, because in future whenever you want to relate something to a Unit, you now have to put 2 bits of info in the related table.
 
I don't know. I have never used the strongly typed data sets before.

Double clicking in the .XSD file, the Properties pane on the right updates to show a DataSet Name value with "AMS_2007DataSet1". Changing that value to remove the 1 suffixes does not cause any conflicts, but there is still 2 build errors about AMS_2007DataSet1DataTable now being missing.
Seems to resolve by doing a global find/repl for AMS_2007DataSet1 -> AMS_2007DataSet

I recall in the past seeing the DS name play tricks like that, but it's been many years..
 
Back
Top Bottom