This is a nice example of how to pass a delimitted list of values to SQL Server and perform some kind of dbase function with those whether that be an UPDATE, DELETE or whatever.
First here is the sample stored procedure we are going to call updating each company sent to it by the PK value, id_company
USE [my_dbase]
GO
CREATE PROCEDURE [dbo].[p_UpdateCompany]
@id_assign int = NULL
AS
BEGIN
SET NOCOUNT ON;
UPDATE Companies
SET markedfordeletion = 1 --or whatever could be a delete statement as well
END
Next, here is the VB.NET code used to call the sproc
Protected Sub btnCompanySubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strConnection As SqlConnection
Dim strSql As String
Dim cmd As SqlCommand
Dim CompanyValues As String = txtid_company.Text
Dim CompanyList As New ArrayList
CompanyList.AddRange(Split(CompanyValues, ","))
strConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conString_Repository").ConnectionString)
strSql = "p_UpdateCompany"
cmd = New SqlCommand(strSql)
cmd.CommandType = CommandType.StoredProcedure
For i As Integer = 0 To CompanyList.Count - 1
Dim CompanyVal As Integer = CompanyList(i)
cmd.Parameters.Add("@id_Company", SqlDbType.Int, CompanyVal)
Try
strConnection.Open()
cmd.Connection = strConnection
cmd.ExecuteNonQuery()
Finally
strConnection.Close()
End Try
Next
End Sub
<form id="form1" runat="server">
<div>
<table id="Companies">
<tr>
<td>Enter id_company values:<br />
(separated by commas)</td>
<td><asp:TextBox ID="txtid_company" runat="server" TextMode="MultiLine" Rows="5" Columns="25" /></td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnCompanySubmit" runat="server" onclick="btnCompanySubmit_Click" Text="Submit" />
</td>
</tr>
</table>
</div>
</form>