Results 1 to 16 of 16

Thread: [RESOLVED] [2008] MDB not updating with da.update

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    62

    Resolved [RESOLVED] [2008] MDB not updating with da.update

    I think it was working a few days ago but now it's not. The funny thing is if I have the mdb open and I run this, the values get replaced with "#Deleted" and when I close it and reopen they are gone. But, if I have it closed, nothing happens.

    What could be the problem?

    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            OpenFileDialog1.Filter = "mdb files(*.mdb)|*.mdb"
    
            OpenFileDialog1.ShowDialog()
    
            con.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & OpenFileDialog1.FileName
            con.Open()
            sql = "Select * From Files"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "Files")
    
    
            maxrows = ds.Tables("Files").Rows.Count
            ReDim filename(maxrows)
            ReDim setid(maxrows)
            ReDim filesize(maxrows)
    
            For i = 0 To maxrows - 1
                setid(i) = ds.Tables("Files").Rows(i).Item(0)
                filename(i) = ds.Tables("Files").Rows(i).Item(2)
                filesize(i) = ds.Tables("Files").Rows(i).Item(4)
            Next
            Dim filename2 As String() = DirectCast(filename.Clone(), String())
            Array.Sort(filename, setid)
            Array.Sort(filename2, filesize)
    
            Dim cb As New OleDb.OleDbCommandBuilder(da)
    
            For i = 0 To maxrows - 2
                If filename(i) = filename(i + 1) And setid(i) = setid(i + 1) Then
                    RichTextBox1.Text = RichTextBox1.Text & vbCrLf & setid(i)
                    RichTextBox1.Text = RichTextBox1.Text & vbCrLf & setid(i + 1)
                    RichTextBox2.Text = RichTextBox2.Text & vbCrLf & filename(i)
                    RichTextBox2.Text = RichTextBox2.Text & vbCrLf & filename(i + 1)
                    RichTextBox3.Text = RichTextBox3.Text & vbCrLf & filesize(i)
                    RichTextBox3.Text = RichTextBox3.Text & vbCrLf & filesize(i + 1)
                    If filesize(i) > filesize(i + 1) Then
                        ds.Tables("Files").Rows(i).Delete()
                        da.Update(ds, "Files")
                    ElseIf filesize(i) < filesize(i + 1) Then
                        ds.Tables("Files").Rows(i + 1).Delete()
                        da.Update(ds, "Files")
                    Else
                        MsgBox(filename(i) & " has a dupe filesize")
                    End If
                End If
            Next
            con.Close()
        End Sub
    Last edited by rhijaen; Sep 29th, 2008 at 10:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width