none
Add and Delete Record in Database Using access 2010 and vb 2010

    Question

  • I dragged the dataset on my from as textboxes and not as datagrid. I have a command button for "ADD" which changes to "SAVE" when clicked. How would I add a new record on my database based on the info that I will type on the textboxes? Also, how would delete the current record that is displayed on my form? and on the database it should delete the entire row in order to avoid null values.

    thanks!

    Saturday, June 16, 2012 12:03 PM

Answers

All replies

  • Hello ixthe3rd,

    I dragged the dataset on my from as textboxes and not as datagrid. I have a command button for "ADD" which changes to "SAVE" when clicked. How would I add a new record on my database based on the info that I will type on the textboxes? Also, how would delete the current record that is displayed on my form? and on the database it should delete the entire row in order to avoid null values.

    thanks!

    i wrote some motnhs ago this sample whit access and Vb2010, http://code.msdn.microsoft.com/Esempio-di-utilizzo-file-4d9b07a8

    Regards. 


    Saturday, June 16, 2012 12:06 PM
  • I'm sorry sir but I can't understand it. It is in Italian.
    Saturday, June 16, 2012 12:12 PM
  • Hello ixthe3rd,

    I'm sorry sir but I can't understand it. It is in Italian.

    I understand, the weather will execute the translation of the comments, but sisntassi of language remains the same, quey Insert, Delete and UDPATE, that is they allow you to enter edit and delete records from an Access file, but you can follow this example.

    http://msdn.microsoft.com/en-us/library/bb243852(v=office.12).aspx

    Regards.


    Saturday, June 16, 2012 12:23 PM
  • does this make use of the databindingsource? 
    Saturday, June 16, 2012 12:41 PM
  • Hello ixthe3rd,

    does this make use of the databindingsource? 

    It depends, the latest example posted does not use madevi use OleDb classes to its wired connection, OleDbCommand to query, but in your case since you run the wizard in the dataset have available the wizard to create queries insert, Update and Delete can be incorporated into the TableAdapter, select the DataSet, right click and choose New query, has the wizard to create custom queries, then it becomes difficult to explain in words when you're starting out, i can recommend to look at some examples that you find on forums or Msdn Library.

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/923a71ef-a4c2-4dfd-833b-c18051dc99ad/

    Regards.


    Saturday, June 16, 2012 12:49 PM
  • Sorry I am quite a noob on this.. this is how I coded my "EDIT" 

           Me.Validate()
           Me.MASTERLISTBindingSource.EndEdit()
           Me.TableAdapterManager.UpdateAll(Me.PAYROLLDBDataSet)

    How about adding and deleting a record?

    Saturday, June 16, 2012 12:56 PM
  • Hello ixthe3rd,

    Sorry I am quite a noob on this.. this is how I coded my "EDIT" 

           Me.Validate()
           Me.MASTERLISTBindingSource.EndEdit()
           Me.TableAdapterManager.UpdateAll(Me.PAYROLLDBDataSet)

    How about adding and deleting a record?

    Forms should have on the BindingNavigator with three button with a + sign to add, delete one signed - if I remember correctly, and finally one with the symbol of the disk that is used to update the data.

    With the add button "+" press it and insert a blank record, enter the following data within text boxes dowels and the Update button "with the symbol of the disk," and to delete a record using the delete key "- ".

    Regards.


    Saturday, June 16, 2012 1:01 PM
  • Yes it has but what I've done is I created separate buttons for each and I wanted to have a code for each button event. ADD,EDIT,DEL,SAVE.
    Saturday, June 16, 2012 1:04 PM
  • Hello ixthe3rd,

    Yes it has but what I've done is I created separate buttons for each and I wanted to have a code for each button event. ADD,EDIT,DEL,SAVE.

    Add three buttons on Form btnAdItem call them, and btnDeleteIten btnSaveItem, add the click events of these three buttons and run the sample code, concerning the elimination of a record you have more choices, see what you need it most.

     Private Sub btnAddItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddItem.Click
            MASTERLISTBindingSource.AddNew()
        End Sub
        Private Sub btnSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveItem.Click
            Me.Validate()
            Me.MASTERLISTBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.PAYROLLDBDataSet)
        End Sub
        Private Sub btnDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteItem.Click
            MASTERLISTBindingSource.Remove("your value object tipe")
            'or
            MASTERLISTBindingSource.RemoveAt("record index")
            'or
            MASTERLISTBindingSource.RemoveCurrent()
        End Sub

    Regards

    Saturday, June 16, 2012 1:19 PM
  • For some reasons:

    When I click add:

    Me.Validate()
                    Me.MASTERLISTBindingSource.EndEdit()
                    Me.TableAdapterManager.UpdateAll(Me.PAYROLLDBDataSet)
                    MsgBox("Successfully added record to database")

     It only temporarily adds the record in the database but when I close the program, it disappears.

    What could be wrong?

    Saturday, June 16, 2012 1:28 PM
  • Hello ixthe3rd,

    For some reasons:

    When I click add:

    Me.Validate()
                    Me.MASTERLISTBindingSource.EndEdit()
                    Me.TableAdapterManager.UpdateAll(Me.PAYROLLDBDataSet)
                    MsgBox("Successfully added record to database")

     It only temporarily adds the record in the database but when I close the program, it disappears.

    What could be wrong?

    You should also have the load event of the Form Fill method by which the control adapter Popili table in datagrid, also checks the property "Copy to Output Directory" DataBase which is set to "copy always" set it "does not copy ", then verify that the Text property of TextBox in the project, located in the node properties are set DataBinding with the BindingSource control of the project, to give a better idea to see this picture.

    Regards.


    Saturday, June 16, 2012 1:43 PM
  • That's what I did and It's still not working.
    Saturday, June 16, 2012 2:01 PM
  • Hello ixthe3rd,

    That's what I did and It's still not working.

    Then try to rerun the wizard again in the dataset, but first remove all references to the old one as the code inside the class. Once rebuilt the new one drags on Form new elements, remember to first delete all references to the old one, then the DataSet, BindinSource, BindingNavigator and TableAdapter.

    Regards.


    Saturday, June 16, 2012 2:05 PM
  • Is there a way to convert an MS access database to a SQL database? Would using an SQL database  easier than access?

    Saturday, June 16, 2012 2:13 PM
  • Hello ixthe3rd,

    Is there a way to convert an MS access database to a SQL database? Would using an SQL database  easier than access?

    no, you create all the tables and fields needed at this point I suggest SqlCompact on Msdn are several examples of code, however if you keep the field names, the same dataset can retrieve the code.

    http://msdn.microsoft.com/en-us/library/bb546200.aspx

    Regards.


    Saturday, June 16, 2012 2:15 PM
  • solved it, what I did is i did not choose the option to copy on output folder but just manually copied it to my project folder. thanks!
    Saturday, June 16, 2012 3:12 PM
  • Hello ixthe3rd,

    solved it, what I did is i did not choose the option to copy on output folder but just manually copied it to my project folder. thanks!

    You're Welcome, However you choose, you have 3 choices "no copy", "Copy Always" or "Copy if newer" :) .

    Best Regards.


    Saturday, June 16, 2012 3:15 PM