By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,572 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,572 IT Pros & Developers. It's quick & easy.

Updating database

P: n/a
I sent this last week, but am unable to go that far back
in the newsgroup to read the answer, so I'm posting again:

I'm using the Jet.Oledb to connect to an Access 2002
database. I have a form that is supposed to load
information from the database, and then return
information to it. It loads the info okay, but will not
update the database correctly. I get the error
message: "An unhandled exception of
type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll." The code is as follows:

' conSchoolInfo = data connection
' adpSchoolInfo = data adapter
' "School Info" = table in database and dataset
' txt***.Text = Textboxes on form

Private Sub GetSchoolInfo() ' Subroutine
that runs when the form is loaded

conSchoolInfo.Open()
adpSchoolInfo.Fill(datSchoolInfo, "SchoolInfo")
conSchoolInfo.Close()

txtName.Text = datSchoolInfo.Tables
("SchoolInfo").Rows(0).Item("Name")
txtCustomerNumber.Text = datSchoolInfo.Tables
("SchoolInfo").Rows(0).Item("CustomerNo")

txtPostAddress1.Text = datSchoolInfo.Tables
("SchoolInfo").Rows(0).Item("PostAddress1")
txtPostAddress2.Text = datSchoolInfo.Tables
("SchoolInfo").Rows(0).Item("PostAddress2")
txtPostCity.Text = datSchoolInfo.Tables
("SchoolInfo").Rows(0).Item("PostCity")
txtPostState.Text = datSchoolInfo.Tables
("SchoolInfo").Rows(0).Item("PostState")
txtPostCountry.Text = datSchoolInfo.Tables
("SchoolInfo").Rows(0).Item("PostCountry")
txtPostZip.Text = datSchoolInfo.Tables
("SchoolInfo").Rows(0).Item("PostZip")
End Sub

Private Sub SaveSchoolInfo() ' Subroutine
that runs when the form is closed

adpSchoolInfo.Fill(datSchoolInfo, "SchoolInfo")
datSchoolInfo.Tables("SchoolInfo").Rows(0).Item
("Name") = txtName.Text
datSchoolInfo.Tables("SchoolInfo").Rows(0).Item
("CustomerNo") = txtCustomerNumber.Text

datSchoolInfo.Tables("SchoolInfo").Rows(0).Item
("PostAddress1") = txtPostAddress1.Text
datSchoolInfo.Tables("SchoolInfo").Rows(0).Item
("PostAddress2") = txtPostAddress2.Text
datSchoolInfo.Tables("SchoolInfo").Rows(0).Item
("PostCity") = txtPostCity.Text
datSchoolInfo.Tables("SchoolInfo").Rows(0).Item
("PostState") = txtPostState.Text
datSchoolInfo.Tables("SchoolInfo").Rows(0).Item
("PostCountry") = txtPostCountry.Text
datSchoolInfo.Tables("SchoolInfo").Rows(0).Item
("PostZip") = txtPostZip.Text

conSchoolInfo.Open()
adpSchoolInfo.Update(datSchoolInfo)
conSchoolInfo.Close()
End Sub
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Cor
Hi Robert,
The first thing I should do in both routines is:
Than you can see what happens (and in this sequence)
\\\
Private Sub SaveSchoolInfo() ' Subroutine Try
..
..
..
..
conSchoolInfo.Open()
adpSchoolInfo.Update(datSchoolInfo)
conSchoolInfo.Close()

Catch oleDbEx As OledbException
MessageBox.Show(oleDbEx.ToString, "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
///
Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.