ADO.NET :: ExecuteNonQuery Using Stored Procedure Will Not Delete Record (SQLDataAdapter)
Sep 6, 2010
I'm using VB.net 2.0 with a SQL server (2005) backend db. I've got a very odd problem. I'm trying to use a stored procedure with a parameter to delete a record from a table. I've tested the stored procedure by running it directly from visual studio and it works fine, but when running it through my application nothing happens. There's no error and it appears to have worked but the record is not deleted.
I've checked permissions on the backend db and giving the network ASPNet account the db owner role has no effect either.
Here's the code, there are 3 layers - the webform code, then the business logic class, then the dataconnection class.
'firstly the original code that is run from the webform when the user selects to delete the record
Partial Public Class NewPerson
Inherits System.Web.UI.Page
Private newConn As New DBConnection
Private currentNewRequest As New NewRequest(newConn)
Protected Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim requestID As Integer = CInt(Me.lblRecordID.Text)
Me.currentNewRequest.newRequestID = requestID
Me.newConn.openConnection()
Me.currentNewRequest.DeleteRecord()
Me.newConn.closeConnection()
End Sub
End Class
'the business logic class that is called to set the parameters etc. The newRequestID integer is set at 19, I have checked this out.
Public Class NewRequest
Private dBConnection As DBConnection
Public newRequestID As Integer
Public Sub New(ByVal dBConnection As DBConnection)
'check params
If dBConnection Is Nothing Then
Throw New ArgumentNullException("dBConnection")
End If
Me.dBConnection = dBConnection
End Sub
Public Sub DeleteRecord()
'This sub deletes a request
With Me.dBConnection
.AddParameter("@newrequestID", SqlDbType.Int, 0, newRequestID)
.ExecNonQuerySP("sp_DeleteNewRequest")
End With
End Sub
End Class
'then the data connection class
Imports System.Data.SqlClient
Public Class DBConnection
Private _ParamList As SqlParameterCollection
Private _MyComm As New SqlCommand
Private _ConnectionStr As String = ConfigurationManager.ConnectionStrings("Conn").ToString
'shared connection
Dim conn As New SqlConnection(_ConnectionStr)
'the parameter is added
Public Sub AddParameter(ByVal ParamName As String, ByVal paramType As Data.SqlDbType, ByVal Paramlength As Int16, ByVal ParamValue As String)
MyComm.Parameters.Add(ParamName, paramType, Paramlength)
If ParamValue = Nothing Or ParamValue = "00:00:00" Or ParamValue = "" Then
_MyComm.Parameters(ParamName).Value = DBNull.Value
Else
_MyComm.Parameters(ParamName).Value = ParamValue
End If
End Sub
'and this is where the stored procedure is supposed to run, no errors are generated
Public Sub ExecNonQuerySP(ByVal SPName As String)
Dim MyAdapter As New SqlDataAdapter(_MyComm)
_MyComm.CommandType = CommandType.StoredProcedure
_MyComm.CommandText = SPName
_MyComm.Connection = conn
If Not _MyTrans Is Nothing Then
_MyComm.Transaction = _MyTrans
End If
Try
_MyComm.ExecuteNonQuery()
Catch ex As Exception
Dim errorMessage As String = ex.GetType.ToString & " " & ex.Message.ToString
System.Web.HttpContext.Current.Session("DBError") = "True"
System.Web.HttpContext.Current.Session("DBEx") = errorMessage
Throw ex
Finally
End Try
End Sub
Public Sub openConnection()
conn.Open()
End Sub
Public Sub closeConnection()
conn.Close()
End Sub
End Class
The stored procedure looks like this:
ALTER PROCEDURE sp_DeleteNewRequest
/*this sp is used to delete a new account request record*/
@newrequestID int
AS
DELETE FROM NewAccountRequest WHERE
NewRequestID = @newrequestID
View 4 Replies
Similar Messages:
Jun 28, 2010
Im using above to makes sure that record is inserted to the SQL database before executing another function, but for some reason even if the record is NOT inserted other function has been called.(Other function is t update a Flag)
look at my code below and see where it goes wrong??
Part of the .Net Code
=============================================================
Private Sub GetAndInsert()[code]....
I have a feeling it could be that Rolling back is done in both .NET and SP??
View 2 Replies
Dec 10, 2010
I am trying to create a method which will access the database via a SqlDataAdapter. I have passed two parameters month and year. When I run it, I get the error "Object reference not set to an instance of an object". I have posted the complete code below. Please take a look..
[Code]....
View 1 Replies
Jan 26, 2011
In my .aspx page, i have two textbox and one add button and one delete button.
I want simply, when entering data textboxes and click add button, adding to database with stored procedure.
When entering data textboxes and click delete button, delete from database with stored procedure.
How can I do that?
Simply I need 4 code part, add_click(), delete_click(), sp_add, sp_delete
View 1 Replies
Apr 19, 2010
Suppose you have the following... An ASP.NET web application that calls a stored procedure to delete a record. The table has a trigger on it that will insert an audit entry each time a record is deleted. I want to be able to record in the audit entry the username of who deleted the record. What would be the best way to go about achieving this? I know I could remove the trigger and have the delete stored procedure insert the audit entry prior to deleting but are there any other recommeded alternative?
If a username was passed as a parameter to the delete stored procedure, is there anyway to get this value in the trigger that's excuted when the record is deleted? I'm just throwing this out there...
View 4 Replies
Sep 21, 2010
i have bind griview dataSource with Store procedure having join of 3 table how can i update this gridview data using stored procedure?
View 5 Replies
May 16, 2010
I have the following stored procedure:
ALTER PROCEDURE Pro_members_Insert
@id int outPut,
@LoginName nvarchar(50),
@Password nvarchar(15),
@FirstName nvarchar(100),
@LastName nvarchar(100),
@signupDate smalldatetime,
@Company nvarchar(100),
@Phone nvarchar(50),
@Email nvarchar(150),
@Address nvarchar(255),
@PostalCode nvarchar(10),
@State_Province nvarchar(100),
@City nvarchar(50),
@countryCode nvarchar(4),
@active bit,
@activationCode nvarchar(50)
AS
declare @usName as varchar(50)
set @usName=''
select @usName=isnull(LoginName,'') from members where LoginName=@LoginName
if @usName <> ''
begin
set @ID=-3
RAISERROR('User Already exist.', 16, 1)
return
end
set @usName=''
select @usName=isnull(email,'') from members where Email=@Email
if @usName <> ''
begin
set @ID=-4
RAISERROR('Email Already exist.', 16, 1)
return
end
declare @MemID as int
select @memID=isnull(max(ID),0)+1 from members
INSERT INTO members (................................
When I run this page, signup.aspx, provide required fields and click submit, the page simply reloads and the database table does not reflect the newly-inserted record. How do I catch the error messages that might be returned from the sproc? how to change signup.aspx so that the insert occurs.
View 3 Replies
Jul 2, 2010
[Code]....
After this and in the same procedure i want to update the inserted or the updated record which occared in the above code with the follwing update statment :
[Code]....
updating mark is completed successfully if the record is existed (Update Case) but if the record does not exist (new record) ... the update of the mark is not occured ..
View 4 Replies
Jan 20, 2010
I am trying to use a stored procedure to insert new records from aspx page. I have created an stored procedure for that and it works fine but I want to display an error message when record exist. It does not display any error message however it does not insert when record exist. How can I display an error message when record exist flag in stored procedure -
[Code]....
View 7 Replies
Oct 7, 2010
I need to execute a stored procedure which is a simple delete (record) query. Programmaticaly, I want to pass in a parameter "ID1".
Assume I will pass in the ID1 parameter on a delete link click event froma GridView control. What would the code be to execute the existing stored procedure?
ID1 - the parameter and primary key of the source database for the record to be deleted
GridView1 - the GridView control
spDeleteRecord - the stored procedure needing the parameter ID1 and to be executed from C# code
DeleteTableAdapter - an existing TableAdapter for the existing
Here's my start:
[code].....
View 5 Replies
Oct 28, 2010
I need to be able to delete records from a gridview using a stored procedure. My data comes from two sources so the standard delete won't work. I have come up with the code below which deletes a record, but the wrong one. How can I iterate through the rows to delete the row I actually want to delete.
[Code]....
View 7 Replies
Sep 8, 2010
I am trying to update record via stored procedure, but i got error at very start point. Problem is when i click on Edit link button within the Gridview it produce error.
I can populate values from database fine but its produce error when i click on edit link button. see the code below.
[Code]....
[Code]....
View 4 Replies
Dec 10, 2010
i want to know how to call stored procedure in entity framework. how to do code with controller class and with model.
i mean if i want to call insert,update,select,delete stored procedure for entity framework then what are stps i have to follow.
View 2 Replies
Jan 16, 2010
I have two tables dept and employees those table have parent and child relation ship link column is deptno i want to delte department even this departmetn contains employees i want to write storedprocedure for first delte employees and after department if i wrtie these two querys in storedprocedure will i get any problems
Begin
Delete from tbl_employees where Department_Id=@Department_Id
Delete from tbl_Department where Department_Id=@Department_Id
RETURN
END
View 5 Replies
Feb 25, 2016
I have a table and i want to use this table in asp.net page
how i will call the stored procedure on the basis
of Stored procedure's Action .
CREATE TABLE Std_Enquiry(
StdID int IDENTITY(1,1) PRIMARY KEY CLUSTERED ,
FirstName varchar(50) ,
LastName varchar(50) ,
[Code].....
View 1 Replies
Apr 2, 2010
This is surareddy. i nead some small clarification in the "Stored Procedure"
how to convert the oracle Stored Procedure to sqlserver2005/2008 Stored Procedure.
right now i am enhancing the project that project already developed the oracle Stored Procedure. now our company is using sqlserver 2005/2008.
how to convert the Oracle Stored Procedure to sqlserver 2005 Stored Procedure
View 4 Replies
Dec 9, 2010
Initially, I have tried to use stored procedure. But I changed my mind and preferred to call sql query in codebase with command text. However, it stills tries to find initially-called stored procedure (which is neither called or exists).I think that it is related caching. But I tried it with different browsers it did not work.What might be the reason?
View 4 Replies
Dec 3, 2010
how to Delete Child Record And Later Delete The Parent Record if it has no child
Trigger might be the answer but i don t know how!
View 1 Replies
Jan 28, 2011
I could probably figure this out if I tried to, but I have been working so long on code, I'm a little fried
I have a stored procedure, and I want to execute another stored procedure during a time period of lets say 1/1/2011 to 12/31/2011
How Would I accomplish this?
View 4 Replies
Jan 18, 2010
Does anybody if it is possible that a stored procedure returns rows which is the result of the execution of another sp? Something like..
[Code]....
View 11 Replies
May 13, 2010
i want to return output parameter from 1 storeprocedure. into another stored procedure.
View 7 Replies
Nov 23, 2010
how can I create stored procedure and write my select statement in it, I know how to create dataset then put type stored procedure and assign it to the sp ... what I want is writing my sp... how can I make it ?
check the following code, this is what I want to write put I don't know where or how !
CREATE STORED PROCEDURE SP_CATEGORY
@CATEGORY VARCHAR(30)
AS
BEGIN
SELECT LATIN_NAME, ENGLISH_NAME, ARABIC_NAME, CATEGORY
FROM FLORA, CATEGORY_LIST
WHERE FLORA.CATEGORY=CATEGORY_LIST.CATEGORY_NAME AND CATEGORY_LIST.CATEGORY_NAME IN (SELECT * FROM SPLITLIST(@CATEGORY, ','))
END
where can I write this code ?!
View 5 Replies
Aug 24, 2010
I have a database linked to a calendar. I had a peice of code that retrieved dates from a database and populated the calendar. I wanted to tidy up my code using stored procedures (they seem neater & i assume there's a benefit somewhere). so i came up with this, however it's not working. The calendar displays, but it's not being populated with the database entries. The SqlCommand & SqlParameter I have working elsewhere in my code; as with the SqlDataAdapter (which also worked before i tried to conver to a storedprocedure!) but combining these three (SqlCommand, SqlParameter & SqlDataAdapter) seem to be causing me problems.It's probably something stupid but if someone could take a look and point me in the right direction,
[Code]....
[Code]....
View 2 Replies
Jan 27, 2011
I have a gridview with edit and delete parameters enabled. When I click on the edit link, I can edit the record successfully. However when I click on the delete link, nothing happens (the record does not get deleted).
View 5 Replies
Sep 14, 2010
I created a ListView and attempted to delete a record using the delete button and native procedures. It failed and threw an error.Pass in a valid dictionary for delete or change your mode to OverwriteChangesIn researching this issue, it appeared there is a problem with the list view when deleteing and
ConflictDetection is set to
[Code]....
[Code]....
[Code]....
[Code]....
[Code]....
[Code]....
[Code]....
[Code]....
[Code]....
View 1 Replies