Having Trouble Deleting Row, Using VB. NET and Access Database

mism
01-13-2004, 08:40 PM
Hello, Im new to programming in VB.NET (still a college student...teaching my self VB.NET) and was working on a simple Form that would access the sample DataBase "Northwind". I was able to Update, Add and Submit Query's using my form, but I'm having trouble getting it to Delete. I don't know if I'm on the right track...if anyone has advice...its more than welcome...thanks

The whole code can be viewed here (http://nike.cecs.csulb.edu/~earzola/Form1.vb)

or the project can be downloaded here (http://nike.cecs.csulb.edu/~earzola/MyFirstVBProject.zip)

oh yeah...when i run the program it says:
A first chance exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

'here is the Event when i click the Delete Button
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

tbxCustId.ReadOnly = False
Dim connDel As OleDbConnection 'Declare connection
Dim adptDel As OleDbDataAdapter 'Declare data Adapter
Dim cmdDel As OleDbCommand

Try

connDel = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source" & _
"= C:\Northwind.mdb;Password=;") 'Instatiate conn
connDel.Open()

adptDel = New OleDbDataAdapter(txbQuery.Text, connDel)
cmdDel = New OleDbCommand("DELETE FROM Customers WHERE CustomerID='" & tbxCustId.Text & "'; ", connDel)

adptDel.DeleteCommand = cmdDel
adptDel.DeleteCommand.Connection = connDel
adptDel.DeleteCommand.ExecuteNonQuery()

Catch SqlError As System.Data.SqlTypes.SqlTypeException
MessageBox.Show("ERROR WITH THE DELETE SQL STATEMENT")

Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)

Finally
connDel.Close()
adptDel.Dispose()

End Try

End Sub

Optikal
01-13-2004, 10:28 PM
there is no need to create a data adapter. Just call .ExecuteNonQuery() on the cmdDel Command object

mism
01-13-2004, 10:44 PM
there is no need to create a data adapter. Just call .ExecuteNonQuery() on the cmdDel Command object

I commented out the Data Adapter (adptDel) and tried:

cmdDel.ExecuteNonQuery()

Got the same error....

Optikal
01-13-2004, 10:48 PM
are you sure you have appropriate permissions to delete this table, and that it doesn't have dependent records in another table (referential integrity constraint). Try executing your SQL statement in Query Analyzer, or whatever you SQL tool of choice is.

mism
01-14-2004, 12:37 AM
are you sure you have appropriate permissions to delete this table, and that it doesn't have dependent records in another table (referential integrity constraint). Try executing your SQL statement in Query Analyzer, or whatever you SQL tool of choice is.

*mism shakes his head and laughs*
Omg...yes...your right...i totally forgot about that...the only rows i can delete are the ones I added... because those are NOT linked to other tables...

thank you very much :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum