Results 1 to 9 of 9

Thread: Problem in delete records

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Problem in delete records

    hi to all:

    I would like to delete all records in an field of my database and I have this code:

    Code:
    Dim sql1 As String
            
            Dim connection As New OleDb.OleDbConnection(String.Format("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & drive & IDempresa))
            connection.Open()
            
            Dim adapter As OleDb.OleDbDataAdapter
    
            sql1 = "select *" & _
            " from balancetegeral" & _
            " order by id"
    
            adapter = New OleDb.OleDbDataAdapter(sql1, connection)
            Dim commandbuilder As New OleDb.OleDbCommandBuilder(adapter)
            adapter.DeleteCommand = commandbuilder.GetDeleteCommand
            
            Dim dt As New DataTable
            adapter.Fill(dt)
    
            
            For Each r As DataRow In dt.Rows
                If r.Item("mensaisdebito") Then
                    r.Delete()
                End If
            Next
    
            'Update database.  
            adapter.Update(dt)
    
            connection.Close()
    In the instruction in bold I have this error:
    Conversion from type 'DBNull' to type 'Boolean' is not valid.

    Any help please

    Thanks

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problem in delete records

    Why not just use a garden variety SQL DELETE query?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Problem in delete records

    Sory but with VS2008 i don't know do this...
    Can you tell me the way to do?

    Thanks

  4. #4
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Problem in delete records

    It's not a VB2008 thing. It's a ADO.NET thing.

    Code:
    Dim MyCom as new OledbCommand("DELETE FROM Table WHERE Column IS NOT NULL", Conn)
    
    try
       MyCom.Executenonquery
    catch ex as OledbException
       
    end try

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Problem in delete records

    ok...sory

    Thanks

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Problem in delete records

    Nothing to be sorry for....you might find this of interest.

    http://www.vbforums.com/showthread.php?t=466658

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Problem in delete records

    yes...it is

  8. #8
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: Problem in delete records

    If you say so. I was simply pointing out that you were blaming the wrong thing. If you didn't know, then now you do. It's all a part of learning.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2004
    Posts
    1,414

    Re: Problem in delete records

    No doubt...and I'm thankfull for all this posts...
    I'm learn day by day,and off course the VBforums it's my house to learn more and more...

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