I have posted below a function I wrote to import fields into an existing access mdb database from a text file.
Each line is correctly read and parsed, in fact it appears to run perfectly, I get no error messages, and yet the database is unchanged after running the code.
Private Sub ImportCatDescriptions()
Dim sw As System.IO.StreamReader
Dim IDescText, IDText, OrigID, OrigDESC As String
Dim LinesImported, OrigIDKey, OrigLang As Integer
Dim tText(1) As String
Dim NewLine As String
Dim LF, SkipLine As Boolean
Dim dr As DataRowView
Me.taTYPE_DESC.Fill(Me.PublicationsDataSet1.TYPE_DESC)
Me.taITEM_TYPE.Fill(Me.PublicationsDataSet1.ITEM_TYPE)
LinesImported = 0
sw = New System.IO.StreamReader(Filename, System.Text.Encoding.GetEncoding("iso-8859-1"))
While Not sw.EndOfStream
NewLine = sw.ReadLine
tText(0) = ""
tText(1) = ""
LF = (Not NewLine.Contains(","))
SkipLine = NewLine.Contains("''") Or LF
If Not SkipLine Then
tText = NewLine.Split(",")
IDescText = tText(0)
IDText = tText(1)
If IDText <> "" And IDescText <> "" Then
Me.bsTYPE_DESC.Filter = "ID = '" & IDText & "' AND LANG = '" & Langtodo & "'" 'Filter to check if row exists already
If Me.bsTYPE_DESC.Count = 0 Then 'Item does not already exist
Try
Me.taTYPE_DESC.Insert(IDText, IDescText, Langtodo)
LinesImported += 1
Catch ex As Exception
End Try
Else
dr = Me.bsTYPE_DESC.Current
OrigID = dr.Item("ID")
OrigIDKey = dr.Item("IDKEY")
OrigDESC = dr.Item("DESC")
OrigLang = dr.Item("LANG")
dr.Delete()
[color=#33CC00] 'Me.taTYPE_DESC.Update(IDText, IDescText, Langtodo, OrigID, OrigDESC, OrigLang, OrigIDKey)
'Me.taTYPE_DESC.Delete(OrigID, OrigDESC, OrigLang, OrigIDKey)
Me.bsTYPE_DESC.EndEdit()
Me.taTYPE_DESC.Update(Me.PublicationsDataSet1.TYPE_DESC)
Me.taTYPE_DESC.Insert(IDText, IDescText, Langtodo)[/color] LinesImported += 1
End If
End If
End If
Me.bsTYPE_DESC.EndEdit()
Me.taTYPE_DESC.Fill(Me.PublicationsDataSet1.TYPE_DESC)
End While
'at = Nothing
sw.Close()
End Sub
I have tried using a datarowview to delete rows, no go.
I have tried Updating the Datatable by retreiving the original values and including them in the update command, nothing
I have tried directly datatable.delete, followed by an insert command...
Nothing works!!! And yet I have a dozen other forms that update information in this database flawlessly.
Can someone point out a blinding error ... anything that would cause me such greif.
I am truly at a loss
*PsychoCoder: Added code blocks
This post has been edited by PsychoCoder: 17 September 2007 - 12:17 PM

New Topic/Question
Reply




MultiQuote





|