473,799 Members | 2,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Nov 20 '05 #1
2 1795
<be******@bells outh.net> 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.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


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

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

Nov 20 '05 #2
Got it. Thanks...
"Armin Zingler" <az*******@free net.de> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
<be******@bells outh.net> 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.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
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

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

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2380
by: Tony Stoker | last post by:
I have a .Net web app that adds a record to a SQL database. After the user adds their record I want to have a link that will link them to their new record! The recordID is a AutoNumber in the SQL server... How do I return the recordID after I have added the record?
5
854
by: ST | last post by:
Hi, I'm sort of in a rush here...I'm sort of new to vb.net and I'm trying to write the syntax to check a sql table to see if the record already exists based on firstname and lastname text fields (will match to firstname and lastname in SQL table). I can't figure out the syntax!!! I would like the Error msg to just display and exit the sub if the row exists. help!!!! thanks!
1
6118
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the records in the subform? I have tried undoing both the main form and the subform and I have tried deleting the record in the main form. Thanks! Mark
1
2398
by: KC | last post by:
Hello, I am using Access 2002. WinXP, Template from MS called Orders Mgmt DB. I have tweaked this DB to work for our small co. It has worked pretty well up until I made the mistake of deleting about 80 records from the Orders table. 80 out of a 1000 records. Now our data entry form shows our customer addresses, but not customer order history. When looking at all of the tables, customer, payments, orders, they still have all of the...
3
12297
by: Christoph | last post by:
I'm delving into using ADO.NET for the first time. In fact, I've never done any database work using C# at all so all of this is new to me. Please bear that in mind if I am asking stupid questions. In reading the documentation for the "Update()" method of the SqlDataAdapter class, I see that it "Calls the respective INSERT, UPDATE, or DELETE statements for each inserted, updated or deleted rows in the specified array of DataRow objects"....
5
3784
by: Robert Brown | last post by:
Hi All. I have a routine that checks a SQL Table for all records 3 months prior to a predetermined date, then I insert them into an Archive DB then delete those records from the original table. When I do a "select" for the records, I load them into a dataset, use an "insert" statement to insert the info into the second table (by a for next loop and using executenonquery , then a "delete" statement to remove them.
46
4439
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this film rental record?" Style = vbYesNo + vbQuestion + vbDefaultButton2
6
3860
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called "Generations"), and it allows the user to add, edit and delete the various records of the table. "Generations" table has the following fields: "IDPerson", NamePerson", "AgePerson" and "IDParent". A record contains the information about a person (his name, his...
1
1773
by: Kyosuke18 | last post by:
Hi everyone, I have a problem in deleting a data that is connected on the database.. I tried this code but it shows me an error: Run-time error '-2147217900(80040e14)': Syntax error in string in query expression 'ID=". Here is the code that i did: Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim ab As String cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My...
0
9540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10222
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.