WHAT'S NEW?
Loading...

How to insert record into related tables


I’ve already created simple table that has a relationships among other tables. Actually, lot of research findings how to create a program in Visual Basic.Net that will be able to insert multiple records into related table. This is my big problem how to insert record into related tables in visual basic.net, and lot of practice wondering why, how it could data to be inserted. Sometimes, I was thinking with that solution because I am having a project soon and I already taught only one table to insert record. However, good things I was learned while working for fun having programmed and I was thoughts what if I could try again how to insert data into multiple records. So I’ll try to create tables and has a field names. When you noticed, there’s no proper way doing naming what looks like my database is. The purpose while making this table is to try if it is work. While doing this, I was thinking all other possibilities how to do first. However, although it is challenge for me, so I’ll try over and over again. Accidentally, I made it! Now, I already insert data into related tables in Visual Basic.Net, that’s why I posted it, because this is what I am aim for.

All the diagrams, codes, and queries are stated here.

Relational databases
Dataset diagram

This are queries made from my database:

Query for tblstudent
INSERT INTO `tblstudent` (`Fname`, `Lname`) VALUES (?, ?)

Query for tblenroll
INSERT INTO `tblenroll` (`StudentID`,  `Section`) VALUES (?, ?)

Query for tblsubjects
INSERT INTO `tblsubjects` (`EnrollID`,`TeacherID`,`FirstGrading`) VALUES (?,?,?)

Query for tblteacher
INSERT INTO `tblteacher` (`Fname`) VALUES (?)

We have 5 texboxes in form Fnametextbox,Lnametextbox,FirstGrading,Section, teacher, and 1 button

Me.TblstudentTableAdapter.InsertQueryStudent(FnameTextBox.Text, LnameTextBox.Text)
Me.TblstudentTableAdapter.Update(Me.DbtestingDataSet.tblstudent)
Me.TblstudentTableAdapter.Fill(Me.DbtestingDataSet.tblstudent)
Me.TblstudentBindingSource.MoveLast()

Me.TblenrollTableAdapter.InsertQueryenroll(Me.TblstudentBindingSource.
Current.item("StudentID"), SectionTextBox.Text)
Me.TblenrollTableAdapter.Update(Me.DbtestingDataSet.tblenroll)
Me.TblenrollTableAdapter.Fill(Me.DbtestingDataSet.tblenroll)
Me.TblenrollBindingSource.MoveLast()

Me.TblteacherTableAdapter.InsertQueryteacher(TeacherTextbox.Text)
Me.TblteacherTableAdapter.Update(Me.DbtestingDataSet.tblteacher)
Me.TblteacherTableAdapter.Fill(Me.DbtestingDataSet.tblteacher)
Me.TblteacherBindingSource.MoveLast()

Me.TblsubjectsTableAdapter.InsertQuerysubject(Me.TblenrollBindingSource.
Current.item("EnrollID"), Me.TblteacherBindingSource.Current.
item("TeacherID"), Me.FirstGradingTextBox.Text)
Me.TblsubjectsTableAdapter.Update(Me.DbtestingDataSet.tblsubjects)

MessageBox.Show("Save")


Display record in a grid. It will be create Datatable

Datatable has now field from other tables in order to view in gridview.

0 comments:

Post a Comment