Adding a record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

At the moment I'm building a Windows Form (connected to an Access DB) which has bound controls. Using some examples I created navigation buttons, so far so good

The problem is the following. I want to create an Add button so the user can add a new record to the database. I searched for several examples but unfortunately all the examples use the same technique. They add a new row and fill it already with data
Example

Private Sub ButtonAdd_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ButtonAdd.Clic

Dim Row As DataRow = Customers.Tables(0).NewRow(
Row("CompanyName") = "Hello Fudge Company
Row("ContactName") = "Robert Golieb
Row("ContactTitle") = "Fudge Master

Customers.Tables(0).Rows.Add(Row
End Su

What I want is like an Access form. The user presses the Add button, the user sees a form with blank fields, the user fills them and presses a save-button to save it to the database. I can't find an example anywhere where this is explained.

Can someone help?
 
Hi!

First off the blank form. When the user presses "Add" you just need to empty
all the fields in the form you are making. After the user has filled the
data you need to fetch it to your DataSet (or data carrying class
whichever). The example you provided only added hardcoded data.

If you replace the examples "Hello Fudge Company" with the corresponding
textbox of the form you will get the functionality you are looking for.

Private Sub ButtonAdd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ButtonAdd.Click

Dim Row As DataRow = Customers.Tables(0).NewRow()
Row("CompanyName") = MyForm.CompanyNameTextBox.Text
Row("ContactName") = MyForm.ContactNameTextBox.Text
Row("ContactTitle") = MyForm.ContactTitleTextBox.Text

So the example is correct, you just need to change where you get the data
from.

I hope this helps

//Mikael
Maurice said:
At the moment I'm building a Windows Form (connected to an Access DB)
which has bound controls. Using some examples I created navigation buttons,
so far so good.
The problem is the following. I want to create an Add button so the user
can add a new record to the database. I searched for several examples but
unfortunately all the examples use the same technique. They add a new row
and fill it already with data.
Example:

Private Sub ButtonAdd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ButtonAdd.Click

Dim Row As DataRow = Customers.Tables(0).NewRow()
Row("CompanyName") = "Hello Fudge Company"
Row("ContactName") = "Robert Golieb"
Row("ContactTitle") = "Fudge Master"

Customers.Tables(0).Rows.Add(Row)
End Sub


What I want is like an Access form. The user presses the Add button, the
user sees a form with blank fields, the user fills them and presses a
save-button to save it to the database. I can't find an example anywhere
where this is explained.
 
Back
Top