Deleting a record with ADO.Net using SqlCommand

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    Deleting a record with ADO.Net using SqlCommand

    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.WaitCur sor
    Dim myConnection As New SqlConnection(s trSqlConnection )
    myConnection.Op en()
    strSqlCommand = "SELECT * FROM USAD_10Digit WHERE RecIdx = " &
    intRecIndex
    Dim myCommand As New SqlCommand(strS qlCommand, myConnection)
    myCommand.Execu teNonQuery()
    myConnection.Cl ose()
    Catch
    If Err.Number <> 0 Then
    MsgBox("Error:" & Str(Err.Number) & ControlChars.Cr Lf & _
    Err.Description & ControlChars.Cr Lf & _
    "Generated by " & Err.Source, _
    MsgBoxStyle.Cri tical, Application.Pro ductName)
    End If
    Finally
    Me.Cursor = Cursors.Default
    End Try
    End Sub


  • Armin Zingler

    #2
    Re: Deleting a record with ADO.Net using SqlCommand

    <bellnier@bells outh.net> schrieb[color=blue]
    > 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.WaitCur sor
    > Dim myConnection As New SqlConnection(s trSqlConnection )
    > myConnection.Op en()
    > strSqlCommand = "SELECT * FROM USAD_10Digit WHERE RecIdx = "
    > &
    > intRecIndex
    > Dim myCommand As New SqlCommand(strS qlCommand,
    > myConnection)
    > myCommand.Execu teNonQuery()
    > myConnection.Cl ose()
    > Catch
    > If Err.Number <> 0 Then
    > MsgBox("Error:" & Str(Err.Number) & ControlChars.Cr Lf & _
    > Err.Description & ControlChars.Cr Lf & _
    > "Generated by " & Err.Source, _
    > MsgBoxStyle.Cri tical, Application.Pro ductName)
    > End If
    > Finally
    > Me.Cursor = Cursors.Default
    > End Try
    > End Sub[/color]

    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.publi c.dotnet.framew ork.adonet


    --
    Armin




    Comment

    • Dick Bellnier

      #3
      Re: Deleting a record with ADO.Net using SqlCommand

      Got it. Thanks...
      "Armin Zingler" <az.nospam@free net.de> wrote in message
      news:%23kMxEMPw DHA.1996@TK2MSF TNGP12.phx.gbl. ..[color=blue]
      > <bellnier@bells outh.net> schrieb[color=green]
      > > 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.WaitCur sor
      > > Dim myConnection As New SqlConnection(s trSqlConnection )
      > > myConnection.Op en()
      > > strSqlCommand = "SELECT * FROM USAD_10Digit WHERE RecIdx = "
      > > &
      > > intRecIndex
      > > Dim myCommand As New SqlCommand(strS qlCommand,
      > > myConnection)
      > > myCommand.Execu teNonQuery()
      > > myConnection.Cl ose()
      > > Catch
      > > If Err.Number <> 0 Then
      > > MsgBox("Error:" & Str(Err.Number) & ControlChars.Cr Lf & _
      > > Err.Description & ControlChars.Cr Lf & _
      > > "Generated by " & Err.Source, _
      > > MsgBoxStyle.Cri tical, Application.Pro ductName)
      > > End If
      > > Finally
      > > Me.Cursor = Cursors.Default
      > > End Try
      > > End Sub[/color]
      >
      > Where is the code to delete the record?
      >
      > Instead of mixing Try/Catch and Err.*, you can catch the exception by[/color]
      writing[color=blue]
      >
      > 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[/color]
      ADO.NET[color=blue]
      > not to the VB.NET language): microsoft.publi c.dotnet.framew ork.adonet
      >
      >
      > --
      > Armin
      >
      > http://www.plig.net/nnq/nquote.html
      > http://www.netmeister.org/news/learn2quote.html
      >[/color]


      Comment

      Working...