problem adding a new record to an access database table using a vb.net form

tonymontana

New member
Joined
Feb 28, 2006
Messages
1
Programming Experience
Beginner
hi everyone
i am new to using vb.net and i have a problem.

I have a vb.net form and i am trying to add a new record to an access database table called 'user'.

i have the following code:
-------------------------------------------
Public Class frmAddUsers
Inherits System.Windows.Forms.Form
Private m_cnADONetConnection As New OleDb.OleDbConnection
Private m_daDataAdapter As New OleDb.OleDbDataAdapter
Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
Private m_dtUsers As New DataTable

Windows Form Designer enerated code
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddUser.Click
Dim drNewRow As DataRow = m_dtUsers.NewRow()
drNewRow("Surname:") = txtSurname.Text
drNewRow("Forename:") = txtForename.Text
drNewRow("Username:") = txtUsername.Text
drNewRow("Password:") = txtPassword.Text
drNewRow("UserTypeNo:") = cboUserType.Text
m_dtUsers.Rows.Add(drNewRow)
m_daDataAdapter.Update(m_dtUsers)
End Sub
Private Sub frmAddUsers_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_cnADONetConnection.ConnectionString = _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\University Of Hertfordshire\Project\BookingSystemForHolidayCaravanPark.mdb"
m_cnADONetConnection.Open()
m_daDataAdapter = _
New OleDb.OleDbDataAdapter("Select * From User", m_cnADONetConnection)
m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)
m_daDataAdapter.Fill(m_dtUsers)

End Sub
Private Sub frmAddUsers_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
m_cnADONetConnection.Close()
End Sub
end class

-------------------------------------------

This is the error that i get:
"An unhandled exception of type 'System.Data.OleDb.OleDbException'
occured in system.data.dll

can anyone help please.
thanks in advance
 
Well, once again, I left my crystal ball at the office.... and Microsoft has yet to implement the Web.MindReader namespace, so I am forced to ask WHERE the error ocurrs....

Also, if you put a try catch around the offending code, you can get a more specific error message:

VB.NET:
Try
...put code here ...
Catch sqlEx as System.Data.OleDb.OleDbException
  MessageBox .Show sqlEx.ToString
End Try

-tg
 
Back
Top