Need help deleting and updating items on .net page

J

JJ297

I created a stored procedure to delete the titleID and then insert the
same titleID but also add several classificationIDs that I select from
several check boxes. Here's the stored procedure.

CREATE procedure UpdateTopicsNTitles
@titleID int,
@classificationID int

AS

Begin
delete from titleclassification

where titleID=@titleid

insert into titleclassification

(TitleID, classificationID)
values (@Titleid, @classificationID )

end
GO

I'm having problems coding my button click. I want it to first delete
the titleID from the database then insert the same titleID that's
selected and all of the items checked for the classificationID.

This is what I've tried doing. Can someone tell me what I've done
wrong as it only adds the title and one classificationID.

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim conn As New
Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("TrainUserConnectionString").ConnectionString)

Dim cmd As New Data.SqlClient.SqlCommand
With cmd
.Connection = conn 'the connection
.CommandType = Data.CommandType.StoredProcedure
.CommandText = "UpdateTopicsNTitles"
.Parameters.AddWithValue("@TitleID", DropDownList1.Text)
.Parameters.AddWithValue("@classificationID",
CheckBoxList1.Text)
End With
Try
conn.Open()
cmd.ExecuteNonQuery() 'executes the sql that I assign.
don't need anything back from db
CheckBoxList1.DataBind()
Catch ex As Data.SqlClient.SqlException
Throw New ApplicationException("An error occurred while
trying to insert the record")

Finally
conn.Dispose()
End Try
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top