Hi,
Im moving over from VB6 to .net 2003 but things are not going to well
I have an access db and have designed a VB form with about 16 text boxes to fill from the db.
My connection is ok and I can fill the textboxes ok and move through the db rows ok. My problem happens when I try and update the db. When I do this I get the following error:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
The following line of code is highlighted: Code:
studentadapter.Update(studentcontacts)
Below is some of my code:
Declaring connection Variables:
Public Class Form1
Inherits System.Windows.Forms.Form
Private studcon As New OleDb.OleDbConnection
Private studentadapter As New OleDb.OleDbDataAdapter
Private studentbuilder As OleDb.OleDbCommandBuilder
Private studentcontacts As New DataTable
Private studid As Integer
Private position As Integer = 0
Assigning the connection variables at form load:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
studcon.ConnectionString = "provider=Microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\Scott\My Documents\Visual Studio Projects\test db\frisby's.mdb"
studcon.Open()
studentadapter = New OleDb.OleDbDataAdapter("SELECT * FROM studenttable", studcon)
studentbuilder = New OleDb.OleDbCommandBuilder(studentadapter)
studentadapter.Fill(studentcontacts)
OleDbDataAdapter1.SelectCommand.Parameters("studentid").Value = studid
Me.showcurrentrecords()
End Sub
My code to update that doesn't work:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If studentcontacts.Rows.Count <> 0 Then
studentcontacts.Rows(position)("city") = tbcity.Text
studentcontacts.Rows(position)("country") = tbcountry.Text
studentcontacts.Rows(position)("date of birth") = tbdob.Text
studentcontacts.Rows(position)("email") = tbemail.Text
studentcontacts.Rows(position)("emergnum") = tbemernum.Text
studentcontacts.Rows(position)("emergcont") = tbemrgcontactname.Text
studentcontacts.Rows(position)("First Name") = tbfirstname.Text
studentcontacts.Rows(position)("telephone") = tbhomephone.Text
studentcontacts.Rows(position)("studentid") = tbid.Text
studentcontacts.Rows(position)("last Name") = tblastname.Text
studentcontacts.Rows(position)("marketing") = tbmarketing.Text
studentcontacts.Rows(position)("mobile no") = tbmobilephone.Text
studentcontacts.Rows(position)("nationality") = tbnationality.Text
studentcontacts.Rows(position)("notes") = tbnotes.Text
studentcontacts.Rows(position)("postcode") = tbpostcode.Text
studentcontacts.Rows(position)("street") = tbstreet.Text
studentcontacts.Rows(position)("title") = tbtitle.Text
studentcontacts.Rows(position)("town") = tbtown.Text
studentadapter.Update(studentcontacts)
Can anyone help or see where im going wrong? ive been on this all day now. My 2 books VB.net1.1 databases and teach yourself vb.net 2003 are not being to helpfull!!
Thanks
Scott
Im moving over from VB6 to .net 2003 but things are not going to well
I have an access db and have designed a VB form with about 16 text boxes to fill from the db.
My connection is ok and I can fill the textboxes ok and move through the db rows ok. My problem happens when I try and update the db. When I do this I get the following error:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
The following line of code is highlighted: Code:
studentadapter.Update(studentcontacts)
Below is some of my code:
Declaring connection Variables:
Public Class Form1
Inherits System.Windows.Forms.Form
Private studcon As New OleDb.OleDbConnection
Private studentadapter As New OleDb.OleDbDataAdapter
Private studentbuilder As OleDb.OleDbCommandBuilder
Private studentcontacts As New DataTable
Private studid As Integer
Private position As Integer = 0
Assigning the connection variables at form load:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
studcon.ConnectionString = "provider=Microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\Scott\My Documents\Visual Studio Projects\test db\frisby's.mdb"
studcon.Open()
studentadapter = New OleDb.OleDbDataAdapter("SELECT * FROM studenttable", studcon)
studentbuilder = New OleDb.OleDbCommandBuilder(studentadapter)
studentadapter.Fill(studentcontacts)
OleDbDataAdapter1.SelectCommand.Parameters("studentid").Value = studid
Me.showcurrentrecords()
End Sub
My code to update that doesn't work:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If studentcontacts.Rows.Count <> 0 Then
studentcontacts.Rows(position)("city") = tbcity.Text
studentcontacts.Rows(position)("country") = tbcountry.Text
studentcontacts.Rows(position)("date of birth") = tbdob.Text
studentcontacts.Rows(position)("email") = tbemail.Text
studentcontacts.Rows(position)("emergnum") = tbemernum.Text
studentcontacts.Rows(position)("emergcont") = tbemrgcontactname.Text
studentcontacts.Rows(position)("First Name") = tbfirstname.Text
studentcontacts.Rows(position)("telephone") = tbhomephone.Text
studentcontacts.Rows(position)("studentid") = tbid.Text
studentcontacts.Rows(position)("last Name") = tblastname.Text
studentcontacts.Rows(position)("marketing") = tbmarketing.Text
studentcontacts.Rows(position)("mobile no") = tbmobilephone.Text
studentcontacts.Rows(position)("nationality") = tbnationality.Text
studentcontacts.Rows(position)("notes") = tbnotes.Text
studentcontacts.Rows(position)("postcode") = tbpostcode.Text
studentcontacts.Rows(position)("street") = tbstreet.Text
studentcontacts.Rows(position)("title") = tbtitle.Text
studentcontacts.Rows(position)("town") = tbtown.Text
studentadapter.Update(studentcontacts)
Can anyone help or see where im going wrong? ive been on this all day now. My 2 books VB.net1.1 databases and teach yourself vb.net 2003 are not being to helpfull!!
Thanks
Scott