PC Review


Reply
Thread Tools Rate Thread

Deleting a record with ADO.Net using SqlCommand

 
 
Guest
Posts: n/a
 
      12th Dec 2003
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


 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      12th Dec 2003
<(E-Mail Removed)> schrieb
> 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


--
Armin

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

 
Reply With Quote
 
Dick Bellnier
Guest
Posts: n/a
 
      15th Dec 2003
Got it. Thanks...
"Armin Zingler" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> <(E-Mail Removed)> schrieb
> > 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
>
>
> --
> Armin
>
> http://www.plig.net/nnq/nquote.html
> http://www.netmeister.org/news/learn2quote.html
>



 
Reply With Quote
 
 
 
Reply

« Image | unicode »
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call SqlCommand.ExecuteReader inside another SqlCommand.ExecuteRea =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= Microsoft ADO .NET 9 25th Jan 2007 04:57 PM
Deleting a duplicate record without deleting the data related. =?Utf-8?B?SGVhdGhlck1pY2hlbGxl?= Microsoft Access 3 12th Mar 2005 03:54 PM
permission denied when deleting record but record still deleted =?Utf-8?B?QW5uIFZsbmE=?= Microsoft Access 0 10th Dec 2004 04:45 PM
BUG? SqlCommand incorrectly reports 'The SqlCommand is currently b =?Utf-8?B?QmFzZTY0?= Microsoft ADO .NET 8 14th Oct 2004 07:56 PM
Deleting a record follow by Adding a record will result in getting wrong Index Key problem =?Utf-8?B?TGlzYSBKb25lcw==?= Microsoft VB .NET 0 30th Apr 2004 06:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:24 PM.