Delete records with "in" clause using ado.net

Below is the code, I am trying to execute using ado.net. What am I doing wrong?

    Trying to delete records using ado.net 

    private const string SqlDeleteMultiple = @"
    DELETE FROM [Board]
    WHERE
    [Id] in (@Ids)
    ";

    public void DeleteMultiple(string items)
        {
            ArgumentValidator.ThrowOnNull("item", items);

            /*   var sbItems = new StringBuilder();

               sbItems.Append("'");
               sbItems.Append(items);
               sbItems.Replace(",", "','");
               sbItems.Append("'");*/

            try
            {
                using (var conn = new SqlConnection(_connectionString))
                {
                    conn.Open();
                    using (var cmd = new SqlCommand( SqlDeleteMultiple,conn))
                    {
                        cmd.Parameters.Add(new SqlParameter("@Ids", SqlDbType.VarChar) {Value = items});
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception err)
            {
                _logger.Log(LogLevel.Error, err, "Error calling Delete");
                throw err;
            }
        }

Conversion failed when converting the varchar value ’9,8′ to data type int. If I change SqlDbType to Int.. I get an another error.


Download delete.records.with.in.clause.using.ado.net.zip
Direct Link


Download


Download delete.records.with.in.clause.using.ado.net.zip
Mediafire


Download


Download delete.records.with.in.clause.using.ado.net.zip
GigaPeta


Download

Both comments and pings are currently closed.

Comments are closed.