deleting from a gridview with check boxes

J

JJ297

I have a button on the other page that right now deletes from one
table

How do I set up this part of the code to delete from another table
called resources or a stored procedure I have called DeleteResource?

Dim cn As Data.SqlClient.SqlConnection = New
Data.SqlClient.SqlConnection(SqlDataSource1.ConnectionString)
If chkBox Then
Try
Dim deleteSQL As String = _
"DELETE from Titles WHERE TitleID IN (" + _
gvIDs.Substring(0, gvIDs.LastIndexOf(",")) + ")"
Dim cmd As Data.SqlClient.SqlCommand = New
Data.SqlClient.SqlCommand(deleteSQL, cn)
cn.Open()
cmd.ExecuteNonQuery()
GridView1.DataBind()
Catch Err As Data.SqlClient.SqlException
Response.Write(Err.Message.ToString)
Finally
cn.Close()
End Try
 
J

JJ297

I have a button on the other page that right now deletes from one
table

How do I set up this part of the code to delete from another table
called resources or a stored procedure I have called DeleteResource?

Dim cn As Data.SqlClient.SqlConnection = New
Data.SqlClient.SqlConnection(SqlDataSource1.ConnectionString)
If chkBox Then
Try
Dim deleteSQL As String = _
"DELETE from Titles WHERE TitleID IN (" + _
gvIDs.Substring(0, gvIDs.LastIndexOf(",")) + ")"
Dim cmd As Data.SqlClient.SqlCommand = New
Data.SqlClient.SqlCommand(deleteSQL, cn)
cn.Open()
cmd.ExecuteNonQuery()
GridView1.DataBind()
Catch Err As Data.SqlClient.SqlException
Response.Write(Err.Message.ToString)
Finally
cn.Close()
End Try

Figured it out I checked the box to cascade deleted related records
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top