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
Re: Problem in delete records
Why not just use a garden variety SQL DELETE query?
Re: Problem in delete records
Sory but with VS2008 i don't know do this...
Can you tell me the way to do?
Thanks
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
Re: Problem in delete records
Re: Problem in delete records
Nothing to be sorry for....you might find this of interest. :)
http://www.vbforums.com/showthread.php?t=466658
Re: Problem in delete records
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.
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...