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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update database with changed dataview

Status
Not open for further replies.

sbdproj

Programmer
Sep 22, 2003
22
NL
Hi, My problem is that I can't get my Access database updated. I've made a dataview and made some changes to it with some data that I've taken from a textfile.
In the try statement under finally I close the textfile and now I want to update the database with the changed dataview. How do I do this?

I've generated the OleDbDataAdapter(OleDbDataAdapterP) with the add,delete,update statements automatically from the server explorer. The Dataset(dsP1) also.

Here's my code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DsP1.Clear()
OleDbDataAdapterP.Fill(DsP1)

DV = New DataView(DsP1.Tables("PERSOON"))
DataGrid1.DataSource = DV
DV.Sort = "SBD_ID"
CM = BindingContext(DV)
End Sub

Private Function VerwerkFile(ByVal filenaam As String) As Boolean
Dim regel As String
Dim regelArr() As String
Dim Naam, SBD_ID, Werkgever As String
Dim Verplicht, Gedaan, Besmet As Integer
Dim i As Integer

Try
FileOpen(1, filenaam, OpenMode.Input)
Do While Not EOF(1)
regel = LineInput(1)
regelArr = Split(regel, ",")
Naam = regelArr(0)
SBD_ID = regelArr(1)
Werkgever = regelArr(2)
Verplicht = CInt(regelArr(3))
Gedaan = CInt(regelArr(4))
Besmet = CInt(regelArr(5))

i = DV.Find(SBD_ID)
If i > DV.Table.Rows.Count Or i < 0 Then
MsgBox("Record " & SBD_ID & " Not found", MsgBoxStyle.Information, "Record Not Found")
Else
CM.Position = i
If DV(i).Item("Naam") <> Naam Then
counter += 1
DV(i).Item("Naam") = Naam
ListBox3.Items.Add("wijzig naam " & CStr(counter) & " " & DV(i).Item("Naam") & " " & DV(i).Item("SBD_ID"))
End If
End If
Loop

' MessageBox.Show("Verwerken van de files is gelukt!", "Verwerken textfiles", MsgBoxStyle.OKOnly, MessageBoxIcon.Information)
Return True
Catch
MessageBox.Show("Verwerken van de file " & filenaam & " is mislukt!", "Verwerken textfiles", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
Finally
FileClose(1)
'OleDbDataAdapterP.Update(DsP1))
' UpdateDataSet(DsP1)
'dataview wegschrijven naar db
End Try

End Function
 
probably something like

Code:
me.bindingcontext(dsp1).endcurrentedit
OleDbDataAdapterP.update(dsp1)

or

Code:
cm(dv).endcurrentedit
OleDbDataAdapterP.update(dsp1)

zolang we maar niet besmet geraken

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
What a wonderfull world - Louis armstrong
 
This code: "OleDbDataAdapterP.update(dsp1)" gives the following error now:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

any ideas how to fix this?
 
and this happens even if the dataset is filled correctly? after return true?


Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
What a wonderfull world - Louis armstrong
 
The first time it worked but I got some errors from Access that I couldn't change any records. This was normal due to some referential entigrity rules in my database.
But the second time and so on I started to get this error.

The dataset is filled correctly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top