There’s a lot of way you can play
with VB.NET in inserting record. However, programming getting easier to perform query and act on the same way like traditional query. In traditional way, we write more lines of
code to accomplish what we aim for in our program. In this tutorial, I’m going
to show how to insert records in vb.net using dataset insert query.
In databinding, the generated
code in saving a record into database is the following.
Me.Validate()
Me.TblInformationBindingSource.EndEdit()
Me.TableAdapterAdapter.Update(Me.DBTestDataSet.tblInformation)
Unfortunately, not all the time
we rely on this code. Now, I used my own query that works on the same way. In
your solution explorer, double click the name of your DataSet. Right click and Add
Query… on your table. Click Next… INSERT query, and the following result that
specify what data should the table load.
INSERT INTO `tblInformation`
(`Firstname`, `Lastname`, `Middlename`, `Gender`, `Address`, `Age`,
`DateOfBirth`) VALUES (?, ?, ?, ?, ?, ?, ?)
Question marks may vary the
number of specified columns.
Click Next, name your query and
proceed to Finish.
Me.TblInformationTableAdapter.InsertQuery(FirstnameTextBox.Text,
LastnameTextBox.Text, cbMI.Text,cbGender.Text, AddressTextBox.Text,
AgeTextBox.Text, txtDateOfBirth.Text)
Me.TblInformationTableAdapter.Update(Me.DBTestDataSet.tblInformation)
MessageBox.Show("New records added to your database", "Successfully Saved",
MessageBoxButtons.OK, MessageBoxIcon.Information)
That’s all! You can insert
record into multiple tables.
0 comments:
Post a Comment