This may belong in the C# forum, but I thought it goes here. I have a class with a couple of methods and several properties that match the form on which the user enters data. This class ("Document") represents a document that is in a database or a new document created by the user. The class will be added to a collection when it is created for a new document or from a record in the database. The question is I have a form created and I have a class created, but is there some way to tell the program that the two are related and somehow automatically populate the properties based on the data entry or the data read from the DB? I hope I made this clear. I see it in my head, but not knowing the .NET very well I am not sure if I am making what I want clearly enough for a real response. As I understand what I should do, is put the real work in the class and use the form as a vehicle to load the class. Once I have a collection I can do all sorts of things with all or each of the items.
Document Form data entry = 1 Document
Data read from database = 1 Document
Several Related Documents = 1 Collection
Do things with the Collection including display the data from a document in the same form as the data entry.
I really appreciate your input. If I have not been clear enough I will gladly answer any questions. I do something similar to this in Access 2010 using VBA. But I lost track of my programming and it is a kluge. I have the class there too, but I don't use it properly and I am constantly reading and writing to the DB. This covers changes to the data just fine, but it just isn't as clean as I wanted.
Loading
Sam HobbsPosted Mar 6, 2012, 4:36 AM
When you have created a data source, and if you are viewing the database design view (or correction; I think it is the design view for the form), then in the data sources window you can click on a table node and there will be a combobox that will drop down and provide options for what type of controls you want to generate. I am sorry I am being vague but hopefully you will figure it out. You can change the type of controls that will be generated when you drag a table or a field from the data sources window to the form. This is how you can specify whether you want a grid view or a details view. I do not know how much of this applies to the Entity Framework. You can play around with this stuff. There are many articles in this web site that can help you. There are also walk throughs in the MSDN that show how to do this stuff and some of them can help.
Scott StewartPosted Mar 6, 2012, 1:25 PM
Scott StewartPosted Mar 6, 2012, 3:59 AM
Once I open the data base I will present the first record in the subset I have chosen. For example, there are 1796 records for one county. Given a particular tract of land I may only be interested in a subset of 100 of those records. Or I may select another 100 from those 1700 for a new tract of land. While I am working I want to save that subset in the collection of document classes. When I am done working they can all go back to the data base until tomorrow. I may add new records to that set of county records and those new records may or may not belong to the current subset. My database is not one table. It is a large relational database. I figure when I make the connection and open the DB as you describe, I can find the open statement and modify it with an SQL statement that will give me the records I need with the right inner or outer joins as needed. The subset of records for a particular tract of land is defined by a simple table that relates a record ID with a subset ID. I am more interested in saving the data from a particular record being shown in the form in an instance of a class and how that instance is related to the properties of the form. I want that instance to be aware of any changes made to the data and save the data as needed. How I can bind the properties of the form to the properties of an instance of a document class. With all the bells and whistles in VS2010 Pro I figure there must be something that I click on that relates the properties of one to the properties of the other. Otherwise I have to just set all the properties with 20 statements of code "this=that." No problem, but I figured there is a better way.
Sam HobbsPosted Mar 6, 2012, 1:25 AM
There are many ways to do it. You can benefit from a good book about C# and .Net and databases. Fortunately this web site has many articles that can help. You can try my Database Table Update in a DataGridView without Writing Code but there are many more articles. My article uses TableAdapters but the newest technology is Entity Framework. My article shows how to create a DataGridView to show the data in a grid but it is quite easy to create a "details" view that shows one record at a time.