Deleting a record with ADO.Net using SqlCommand

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been trying to delete a record with the following code, but not
receiving any results, not even an error message. I have verified that I am
passing a valid record index and that my connection is correct. I'm new to
ADO.Net and this is driving me crazy. Thanks in advance.

Private Sub RecDel(ByVal intRecIndex As Integer)
Try
Me.Cursor = Cursors.WaitCursor
Dim myConnection As New SqlConnection(strSqlConnection)
myConnection.Open()
strSqlCommand = "SELECT * FROM USAD_10Digit WHERE RecIdx = " &
intRecIndex
Dim myCommand As New SqlCommand(strSqlCommand, myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close()
Catch
If Err.Number <> 0 Then
MsgBox("Error:" & Str(Err.Number) & ControlChars.CrLf & _
Err.Description & ControlChars.CrLf & _
"Generated by " & Err.Source, _
MsgBoxStyle.Critical, Application.ProductName)
End If
Finally
Me.Cursor = Cursors.Default
End Try
End Sub
 
I have been trying to delete a record with the following code, but
not receiving any results, not even an error message. I have
verified that I am passing a valid record index and that my
connection is correct. I'm new to ADO.Net and this is driving me
crazy. Thanks in advance.

Private Sub RecDel(ByVal intRecIndex As Integer)
Try
Me.Cursor = Cursors.WaitCursor
Dim myConnection As New SqlConnection(strSqlConnection)
myConnection.Open()
strSqlCommand = "SELECT * FROM USAD_10Digit WHERE RecIdx = "
&
intRecIndex
Dim myCommand As New SqlCommand(strSqlCommand,
myConnection)
myCommand.ExecuteNonQuery()
myConnection.Close()
Catch
If Err.Number <> 0 Then
MsgBox("Error:" & Str(Err.Number) & ControlChars.CrLf & _
Err.Description & ControlChars.CrLf & _
"Generated by " & Err.Source, _
MsgBoxStyle.Critical, Application.ProductName)
End If
Finally
Me.Cursor = Cursors.Default
End Try
End Sub

Where is the code to delete the record?

Instead of mixing Try/Catch and Err.*, you can catch the exception by writing

Catch ex As Exception

In the catch block, you can get exception information from 'ex'.

There is a group for ADO.NET questions (your question is related to ADO.NET
not to the VB.NET language): microsoft.public.dotnet.framework.adonet
 
Got it. Thanks...
Armin Zingler said:
Where is the code to delete the record?

Instead of mixing Try/Catch and Err.*, you can catch the exception by writing

Catch ex As Exception

In the catch block, you can get exception information from 'ex'.

There is a group for ADO.NET questions (your question is related to ADO.NET
not to the VB.NET language): microsoft.public.dotnet.framework.adonet


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top