Saturday, February 25, 2012

Records dont get deleted from the database!

I am using this code to delete records from a table in the database that has two fields (both are primary keys) I am not getting any error, but nothing gets deleted. Thanks for the help.

Code:

protectedvoid btnRemove_Click(object sender,EventArgs e)

{

Remove();

Response.Redirect("RegisteredCompanies.aspx");

}

protectedvoid Remove()

{

//update database with filename

//Save Changes

connection.Open();

using (SqlTransaction trans = connection.BeginTransaction())

{

try

{

SqlHelper.ExecuteNonQuery(trans,CommandType.StoredProcedure,"spRemoveCompany",newSqlParameter("@.Userid",getGdUserID(Profile.UserName)),newSqlParameter("@.BusinessID",getBusinessID());

}

catch (Exception err)

{

// throw exception

trans.Rollback();

lblStatus.Text ="An error has occurred in the delete process. Please try again.";

}

}

Here is the stored procedure:

ALTERPROCEDURE[dbo].[spRemoveCompany]

@.Useriduniqueidentifier OUTPUT,

@.BusinessID uniqueidentifier OUTPUT

AS

DELETEFROMAssociations2WHEREUserid = @.Userid AND BusinessID = @.BusinessID

RETURN

You must commit the transaction in your code.

|||

Also, why are you using OUTPUT on your parameters?

|||

yes, I used output in the stored procedure. How do i commit the transaction? Thanks!

|||

Got it working now!! Thanks a lot!!

No comments:

Post a Comment