473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Delete record from SQL DB

Hey, i am trying to delete a record from an SQL database
table named CourseList.

The code i am using is the same code that has worked for
me before. When i run it i get the following error:
An unhandled exception of
type 'System.NullReferenceException' occurred in QPCU
Database frontend.exe

Additional information: Object reference not set to an
instance of an object.

Tells me that oDR = Nothing

Here is the code.

Private Sub DataCourseDelete()
Dim oAdapter As SqlClient.SqlDataAdapter
Dim oBuild As SqlClient.SqlCommandBuilder
Dim oDR As DataRow
Dim strSQL As String
Dim strID As String
Dim strConn As String

' Get Connection String
strConn = ConnectStringBuild()

' Get Primary Key From List Box
strID = CType(lstCourse.SelectedItem,
PDSAListItemNumeric).ID.ToString()

' Find DataRow To Delete
oDR = moDS.Tables("CourseList").Rows.Find(CInt
(strID))
' Mark DataRow for deletion
oDR.Delete()

Try
' Build SQL String
strSQL = "SELECT * FROM CourseList "
' Create New DataAdapter
oAdapter = New _
SqlClient.SqlDataAdapter(strSQL, strConn)
' Create CommandBuild from Adapter
' This will build INSERT, UPDATE and DELETE
SQL
oBuild = New SqlClient.SqlCommandBuilder
(oAdapter)

' Get Delete Command Object
oAdapter.DeleteCommand =
oBuild.GetDeleteCommand()

' Submit DELETE through Adapter
oAdapter.Update(moDS, "CourseList")
' Tell DataSet changes to data source are
complete
moDS.AcceptChanges()

' Reload the list box
CourseListLoad()

Catch oException As Exception
MessageBox.Show(oException.Message)

End Try
End Sub

Nov 20 '05 #1
2 1557
Cor
Hi Mahatma,

When I look at your code I think, where comes that dataset suddenly from the
air from, is it filled or ?????????
oDR = moDS.Tables("CourseList").Rows.Find(CInt
(strID))


I don't know if it is the problem, but can be

Cor

Nov 20 '05 #2
seems like overkill for a simple delete
you could try executing a sql delete command
"delete from CourseList where nameofcoll = " & strID
if you want to delete more records you van use
"delete from CourseList where nameofcoll like( " & strID & ")"
and build your string like this "12, 15, 19"

i know using stored procs is better but this might help ;p

eric
Nov 20 '05 #3

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

Similar topics

1
by: Someonekicked | last post by:
I have a binary file, and I need to delete a specific number of characters in it. The file contains records, each record has a specific length. So the way I wanna handle deleting is that I will...
9
by: Robert Schneider | last post by:
Hi to all, I don't understand that: I try to delete a record via JDBC. But I always get the error SQL7008 with the error code 3. It seems that this has something to do with journaling, since the...
8
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: ...
3
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
3
by: Maria | last post by:
Is there another way to delete the current record in a subform from the main form, another subform or a sub-subform other than setting focus on a field in the subform and using run command...
4
by: Susan Bricker | last post by:
I have a command button on a form that is supposed to Delete the record being displayed. The record is displayed one to a form. The form is not a Pop-Up nor is it Modal. Tracing the btnDelete...
5
by: Bob Bridges | last post by:
Start with two tables, parent records in one and child records in the other, a one-to-many relationship. Create a select statement joining the two. Display the query in datasheet mode. When I...
4
by: Craggy | last post by:
Hi, I am trying to pop up a yes/no message box so that a user can delete a record in a continuous form. The default delete message is a bit sloppy because it seems to move the continuous form to...
5
by: sh26 | last post by:
I can Add and Delete (A, CName, MX and TXT) Dns records on the Dns Server using C# code. The problem I am having is if someone manaully creates a TXT record on the Dns Server, I cannot delete that...
10
beacon
by: beacon | last post by:
Hi everybody, This is probably going to sound unorthodox, but I have to log records that are deleted...I know, go figure. Anyway, I have a form with a (continuous) subform, and on the subform I...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.