Results 1 to 6 of 6

Thread: VB Text Box to Access Table

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    3

    VB Text Box to Access Table

    This is probably a simple process but I can't seem to accomplish it for the life of me. What I'm trying to do is transfer user inputted data from a Visual Basic text box into an Access database. The database consists of only one table with three fields: First Name, Last Name, and ID Number (auto-increment primary key). The VB code I have so far is this:

    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Student_InformationTableAdapter.Fill(Me.WritingCenterStudentInfoDat aSet.Student_Information)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    MsgBox("Record Successfully Saved")
    Me.Close()
    End Sub
    End Class

    I don't know how to code the Submit Button in order to send the data to the table. Any help would be much appreciated. Also, feel free to use small words; I'm rather unexperienced.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB Text Box to Access Table

    At the moment you are retrieving all the data in the table from the database into your app. Do you actually want to do that, or do you just want to add a new record?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    3

    Re: VB Text Box to Access Table

    Definitely the latter; I'm only interesting in adding a new row of data with each click of the Submit button. Thanks for the reply by the way.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB Text Box to Access Table

    If you don't want to retrieve data then you shouldn't be calling Fill, because that's what Fill does. To just add a new record you have two options:

    1. Start with an empty DataTable, create new row, populate it add it to the table and then call Update on a TableAdapter.

    2. Enable DB Direct methods on your DataSet and then call the appropriate Insert method of a TableAdapter, passing the field values directly.

    Option 2 inserts the data directly into the database without using a DataTable as an intermediate store, hence the term "DB Direct".
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    3

    Re: VB Text Box to Access Table

    Thanks greatly; I'll try some of this (probably option 2).

    Edit: could you please give me some sample code for the Insert methods. Also, I'm not exactly sure how to enable DB Direct methods for my DataSet. Sorry, I'm a serious novice.
    Last edited by SilentSc0rch; Mar 24th, 2011 at 04:31 PM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB Text Box to Access Table

    If I recall correctly, once the DataSet is created, whether or not to enable DB Direct methods is controlled by a property of your TableAdapters set in the DataSet designer. You can use the Query Builder to build your query.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width