Results 1 to 4 of 4

Thread: Adding A Record To Access Using VB.Net

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    3

    Adding A Record To Access Using VB.Net

    I have a customer form built in VB.Net with a Name Field, Address Field, City, State, Zip, and Phone number Field. I also have an Access Database with these same fields as a part of a Customer table. I already have my adapter and connection and dataset all setup in VB.Net. I cant figure how to add what i have in these fields on my VB Customer form to the Customer Table in access. I just need to know how to code my addCustomer Button. PLease Help Me!!! Thanx

    Bass

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    3
    My data adapter is named DaCustomerInfo and my dataset is name DsCustomerInfo1. any help with this would be greatly appreciated thanx again for your help!! The Code is below.

    Bass



    Private Sub FrmNewCustomer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    DaCustomerInfo.Fill(DsCustomerInfo1, "Customer")
    Me.CenterToScreen()

    End Sub

    Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
    If MessageBox.Show("Are you sure you want to exit?", "Confirm Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
    Me.Close()
    Else
    End If
    End Sub

    Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
    TxtFirstName.Text = " "
    TxtLastName.Text = " "
    TxtAddress.Text = " "
    TxtCity.Text = " "
    TxtState.Text = " "
    TxtZip.Text = " "
    TxtHomePhone.Text = " "
    TxtCellPhone.Text = " "
    TxtOtherPhone.Text = " "
    TxtFirstName.Focus()

    End Sub

    Private Sub BtnAddCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAddCustomer.Click

    Dim rwCustomer As DataRow = DsCustomerInfo1.Tables("Customer").NewRow 'creates datarow structured as the datarows in dsCustomer1Tables("Customer")
    rwCustomer("First Name") = TxtFirstName.Text
    rwCustomer("Last Name") = TxtLastName.Text
    rwCustomer("Address") = TxtAddress.Text
    rwCustomer("City") = TxtCity.Text
    rwCustomer("State") = TxtState.Text
    rwCustomer("Zip") = TxtZip.Text
    rwCustomer("Home Phone") = TxtHomePhone.Text
    rwCustomer("Cell Phone") = TxtCellPhone.Text
    rwCustomer("Other Phone") = TxtOtherPhone.Text
    DsCustomerInfo1.Tables("Customer").Rows.Add(rwCustomer) 'adds rwCustomer to dataset
    DaCustomerInfo.Update(DsCustomerInfo1) 'persists the new row back to the Access db
    If MessageBox.Show("Would like to add another Customer at this time?", "Add Customer?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.Yes Then

    TxtFirstName.Text = " "
    TxtLastName.Text = " "
    TxtAddress.Text = " "
    TxtCity.Text = " "
    TxtState.Text = " "
    TxtZip.Text = " "
    TxtHomePhone.Text = " "
    TxtCellPhone.Text = " "
    TxtOtherPhone.Text = " "
    TxtFirstName.Focus()

    Exit Sub

    Me.Close()

    End If

    End Sub

    End Class

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    3
    Anyone Out there that can help me out?? I would really appreciate it!!! Thanx

    Bass

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    take a look at the (crude) inventory system i did on www.vb-tech.com.

    there's also lots of examples on this forum, and google. Just try a search.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

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