|
-
Oct 22nd, 2003, 10:25 AM
#1
Thread Starter
New Member
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
-
Oct 24th, 2003, 09:54 AM
#2
Thread Starter
New Member
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
-
Oct 27th, 2003, 10:42 AM
#3
Thread Starter
New Member
Anyone Out there that can help me out?? I would really appreciate it!!! Thanx
Bass
-
Oct 27th, 2003, 04:30 PM
#4
Fanatic Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|