Multiple Tables in MS Access Database !
-
Hi Everyone, I am using MS Access database with VB.NET. My problem is very simple. It is as follows: I have two tables "Class" ( with a field "Class") & "Section"( with a field "Section"). I can fill both this tables of MS Access database programmaticaly thorough VB.NET. There are two textboxes t1 & t2 on the Form to fill corresponding fields "Class" & "Section" of the tables. Now what I want is to fill "Class" field and then "Section" field in such a way that for each entry of "Class" field, there will be entry in "Section" field. e.g. Insert class 1 in textbox t1 Insert setion A in textbox t2 While save, section A must be saved under class 1. Similarly, if I Insert class 1 in textbox t1 Insert section B in textbox t2 then, section B should come under class 1. Similarly, if I insert class 2 and then section A & section B, then both this sections should get stored under class 2. Overall, there should not be any conflict between class and section entries. i.e. each class entries has its corresponding section entries. Hope My issue is clearly. Can someone help me how to do this? Any example would be appreciated. Regards R.S.
-
Hi Everyone, I am using MS Access database with VB.NET. My problem is very simple. It is as follows: I have two tables "Class" ( with a field "Class") & "Section"( with a field "Section"). I can fill both this tables of MS Access database programmaticaly thorough VB.NET. There are two textboxes t1 & t2 on the Form to fill corresponding fields "Class" & "Section" of the tables. Now what I want is to fill "Class" field and then "Section" field in such a way that for each entry of "Class" field, there will be entry in "Section" field. e.g. Insert class 1 in textbox t1 Insert setion A in textbox t2 While save, section A must be saved under class 1. Similarly, if I Insert class 1 in textbox t1 Insert section B in textbox t2 then, section B should come under class 1. Similarly, if I insert class 2 and then section A & section B, then both this sections should get stored under class 2. Overall, there should not be any conflict between class and section entries. i.e. each class entries has its corresponding section entries. Hope My issue is clearly. Can someone help me how to do this? Any example would be appreciated. Regards R.S.
I think you are referring to referential integrity and how to create and maintain a relationship between class and section. In your tables you need to have key fields something like this ClassID Class SectionID ClassID Section ClassID and SectionID are auto increment field and are the primary keys to their tables. When you insert a record in the Class table you should get back the ClassID from the insert method (in SQL Server it is with @@Identity or @Scope_Identity). You now need to use this ClassID when inserting the record into the Section table. Generally these type of linked inserts are wrapped in a transaction so if a Class insert fails then you do not insert a Section record with no related Class record. I suggest you get a book on databases and start working through the examples, you will struggle if you try to use a forum for your primary learning tool.
Never underestimate the power of human stupidity RAH
-
I think you are referring to referential integrity and how to create and maintain a relationship between class and section. In your tables you need to have key fields something like this ClassID Class SectionID ClassID Section ClassID and SectionID are auto increment field and are the primary keys to their tables. When you insert a record in the Class table you should get back the ClassID from the insert method (in SQL Server it is with @@Identity or @Scope_Identity). You now need to use this ClassID when inserting the record into the Section table. Generally these type of linked inserts are wrapped in a transaction so if a Class insert fails then you do not insert a Section record with no related Class record. I suggest you get a book on databases and start working through the examples, you will struggle if you try to use a forum for your primary learning tool.
Never underestimate the power of human stupidity RAH