Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loading a DB from a dataset

Status
Not open for further replies.

aharris2693

Programmer
Jul 15, 2003
45
US
From the research I have done as well as reading previious posts, I have written the following code as a sample to learn the process of reading and updating an Access DB. It all woks fine until the update command. At this point, I get the following message "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll" The new row is being added to the dataset, just not to the database. Has anyone run into this problem before? Any help would be greatly appreciated.


Dim strSQL As String
Dim strConn As String
Dim objDA As OleDb.OleDbDataAdapter
Dim objDS As New DataSet()
Dim intCounter As Integer
Dim strResult As String
Dim objCB As OleDb.OleDbCommandBuilder
Dim objRow As Data.DataRow

strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source='F:\DATA\USERS\HarrisAL\hoteling.mdb'"
strSQL = "Select * From Person"

objDA = New OleDb.OleDbDataAdapter(strSQL, strConn)

objCB = New OleDb.OleDbCommandBuilder(objDA)

objDA.Fill(objDS, "Person")

objRow = objDS.Tables("Person").NewRow
'objRow("PersonID") = 50
objRow("FirstName") = txtFirstName.Text
objRow("LastName") = txtLastName.Text
objRow("Handle") = txtHandle.Text
objRow("Password") = txtPassword.Text

objDS.Tables("Person").Rows.Add(objRow)

objDA.Update(objDS, "Person")



With objDS.Tables(0)
For intCounter = 0 To .Rows.Count - 1
strResult = .Rows(intCounter).Item("FirstName").ToString
MsgBox(strResult)

Next
End With
End sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top