Looked through Forum and appears to me that I have everything mentioned in previous posts so I thought I would post in case someone see's something I missed.
Basically I am trying to add a record to Access DB to no resolve. I was getting errors earlier that I seemed to have corrected now can't figure out why it isn't adding record. Have posted the code so hope someone can help. Currently a VB6 programmer who's trying to teach self the .Net way and occasionally hit stumbling block.
Thanks in advance.
Imports System.Data.OleDb
Public Class PhoneBook
Inherits System.Windows.Forms.Form
Dim objConnection As New OleDb.OleDbConnection( _
"Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = C:\Documents and Settings\Administrator\Desktop\Phonebook.mdb"
Dim objPhBookDA As New OleDb.OleDbDataAdapter( _
"Select * from PhoneBook", objConnection)
Dim objPhBookCB As New OleDb.OleDbCommandBuilder(objPhBookDA)
Dim objDataSet As New DataSet()
Private Sub AddContact()
objPhBookDA.Fill(objDataSet, "PhoneBook"
Dim objRow As System.Data.DataRow
'Create a new DataSet object for this table
objRow = objDataSet.Tables("PhoneBook"
.NewRow
objRow.Item("Name"
= txtName.Text
objRow.Item("Address"
= txtAddr.Text
objRow.Item("City"
= txtCity.Text
objRow.Item("State"
= txtState.Text
objRow.Item("ZipCode"
= txtZip.Text
objRow.Item("Address"
= txtAddr.Text
objRow.Item("HomePhone"
= txtHomePhone.Text
objRow.Item("CellPhone"
= txtCell.Text
objRow.Item("WorkPhone"
= txtWorkPhone.Text
objRow.Item("E-Mail"
= txtEMail.Text
objRow.Item("ContactType"
= cboContact.Text
objRow.Item("Notes"
= txtNotes.Text
objDataSet.Tables("PhoneBook"
.Rows.Add(objRow)
objDataSet.AcceptChanges()
objPhBookDA.Update(objDataSet, "PhoneBook"
End Sub
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
If (txtName.Text = "" And txtHomePhone.Text = ""
Or (txtName.Text = "" And txtWorkPhone.Text = ""
Then
MessageBox.Show("You must enter a Name and PhoneNumber"
Else
AddContact()
End If
End Sub
End Class
Basically I am trying to add a record to Access DB to no resolve. I was getting errors earlier that I seemed to have corrected now can't figure out why it isn't adding record. Have posted the code so hope someone can help. Currently a VB6 programmer who's trying to teach self the .Net way and occasionally hit stumbling block.
Thanks in advance.
Imports System.Data.OleDb
Public Class PhoneBook
Inherits System.Windows.Forms.Form
Dim objConnection As New OleDb.OleDbConnection( _
"Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = C:\Documents and Settings\Administrator\Desktop\Phonebook.mdb"
Dim objPhBookDA As New OleDb.OleDbDataAdapter( _
"Select * from PhoneBook", objConnection)
Dim objPhBookCB As New OleDb.OleDbCommandBuilder(objPhBookDA)
Dim objDataSet As New DataSet()
Private Sub AddContact()
objPhBookDA.Fill(objDataSet, "PhoneBook"
Dim objRow As System.Data.DataRow
'Create a new DataSet object for this table
objRow = objDataSet.Tables("PhoneBook"
objRow.Item("Name"
objRow.Item("Address"
objRow.Item("City"
objRow.Item("State"
objRow.Item("ZipCode"
objRow.Item("Address"
objRow.Item("HomePhone"
objRow.Item("CellPhone"
objRow.Item("WorkPhone"
objRow.Item("E-Mail"
objRow.Item("ContactType"
objRow.Item("Notes"
objDataSet.Tables("PhoneBook"
objDataSet.AcceptChanges()
objPhBookDA.Update(objDataSet, "PhoneBook"
End Sub
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
If (txtName.Text = "" And txtHomePhone.Text = ""
MessageBox.Show("You must enter a Name and PhoneNumber"
Else
AddContact()
End If
End Sub
End Class