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
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