|
-
Apr 7th, 2009, 09:13 AM
#1
Thread Starter
Frenzied Member
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
-
Apr 7th, 2009, 09:15 AM
#2
Re: Problem in delete records
Why not just use a garden variety SQL DELETE query?
-
Apr 7th, 2009, 09:18 AM
#3
Thread Starter
Frenzied Member
Re: Problem in delete records
Sory but with VS2008 i don't know do this...
Can you tell me the way to do?
Thanks
-
Apr 7th, 2009, 09:27 AM
#4
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
-
Apr 7th, 2009, 09:40 AM
#5
Thread Starter
Frenzied Member
Re: Problem in delete records
-
Apr 7th, 2009, 09:42 AM
#6
Re: Problem in delete records
Nothing to be sorry for....you might find this of interest. 
http://www.vbforums.com/showthread.php?t=466658
-
Apr 7th, 2009, 09:54 AM
#7
Thread Starter
Frenzied Member
Re: Problem in delete records
-
Apr 7th, 2009, 11:24 AM
#8
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.
-
Apr 7th, 2009, 11:29 AM
#9
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|