0

I'm trying to insert a new row into students table but its not doing anything. Heres my code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim stAdapter As New StudentSystemDBDataSetTableAdapters.studentsTableAdapter()
    Dim stDataset As New StudentSystemDBDataSet()
    Dim Row As StudentSystemDBDataSet.studentsRow
    Row = stDataset.students.NewstudentsRow

    Row.Student_no = "34"
    Row.Title = "ert"
    Row.Initials = "3434"
    Row.Surname = "erwer"
    Row.Address = "fgsfd"
    Row.Postal_Code = "rwerwe"
    Row.Birthdate = "gogid"
    Row.Gender = "erwrwer"

    stDataset.students.Rows.Add(Row)
    stAdapter.Update(stDataset.students)
End Sub
Steve
  • 5,585
  • 2
  • 18
  • 32
Inaloz_H
  • 41
  • 2
  • 9

1 Answers1

0

The UpdateCommand, InsertCommand and 'DeleteCommand` control how your data is updated, inserted and deleted. This is SQL that is parameterized and then used by the adapter to save your changed.

If you used the wizard to create your adapter, run it again and pay attention to the parts that make your data updatable. It will create these for you, but you have to check the box that tells it to.

If you did not use the wizard, you will need to create the commands manually as well.

Steve
  • 5,585
  • 2
  • 18
  • 32
  • How do you do which? Did you use the wizard to create the adapter? I am assuming you did. – Steve Sep 11 '14 at 15:47
  • The thing is my lecture used exactly the same code I provided and it worked well. He didnt use any of the of commands you gave me. So yes I did use the wizard. Dataset was created, – Inaloz_H Sep 11 '14 at 15:57
  • Your project should have an "XSD" with the name of your database. Double-click on it (or right-click and choose open). Find your table in the data diagram and right-click on it. Choose CONFIGURE. Click next on the wizard and you should see an option that says something like "Create methods to send updates directly...". (NOTE: These direction may vary based on VS version and edition) – Steve Sep 11 '14 at 16:43
  • Still not working. I really dont know what the issue is – Inaloz_H Sep 11 '14 at 18:02