Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi All,

 

I am trying to delete all the records contained in a table.

 

Private Sub DeletePrintedAsset()

 

Dim blnDeleteAsset As Boolean = False

Dim cnADONetConnection As New OleDb.OleDbConnection

Dim daDataAdapter As New OleDb.OleDbDataAdapter

Dim cbCommandBuilder As New OleDb.OleDbCommandBuilder

Dim dtAsset As New DataTable

Dim rowPosition As Integer = 0

Dim strCurrentDBAsset As String

 

'Try

' Open the database connection

 

cnADONetConnection.ConnectionString = _

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" & _

strDatabaseName

cnADONetConnection.Open()

 

' Get all the Assets

 

daDataAdapter = _

New OleDb.OleDbDataAdapter("Select * from PrintSignOut", _

cnADONetConnection)

daDataAdapter.Fill(dtAsset)

 

' Set up the commandbuilder so we can delete the record.

 

cbCommandBuilder = New OleDb.OleDbCommandBuilder(daDataAdapter)

 

Do Until rowPosition = -1

 

' Delete the Issue Record

 

dtAsset.Rows(rowPosition).Delete()

 

' Commit the changes to the actual data souce.

 

daDataAdapter.Update(dtAsset)

Loop

 

' Close the connection to the database

 

cnADONetConnection.Close()

 

'Catch ex As Exception

'MessageBox.Show("An error has occurred! Error: " & ex.Message, _

' "DIntTC Asset Management", MessageBoxButtons.OK, MessageBoxIcon.Error)

'End Try

End Sub

 

When I run this piece of code it comes up with the following error at the "daDataAdapter.Update(dtAsset):

 

"An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

 

Additional information: Dynamic SQL generation for the DeleteCommand is not supported against a SelectCommand that does not return any key column information."

 

Want am I doing wrong?????

Please Help.

Edited by SonicBoomAu

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted

Hi there,

open your connection just as you showed then have a CommandObject take care of the delete....

Dim cmdDelete As OleDbCommand = New OleDbCommand("Delete from PrintSignOut", cnADONetConnection)
cmdDelete.ExecuteNonQuery()

 

Simplicity is beautiful, isn't it....

 

HTH

/Kejpa

Posted

Thank You.

 

I have been pulling my hair out over this for the last week.

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...