Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
How to delete all rows in oracle table based on values in vb.net textbox, TextBox contain values from column1

What I have tried:

This code delete only first row from textbox in oracle table :

For Each name As String In TextBox1.Text.Split(vbNewLine)
str = "Delete from table_1 where column1 in ('" & name & "')"
Posted
Updated 26-Sep-18 5:12am

1 solution

Assuming an open OracleConnection instance called YourConnectionHere:
VB.NET
Using command As New OracleCommand()
    command.Connection = YourConnectionHere
    
    Dim sb As New StringBuilder("DELETE FROM table_1 WHERE column1 IN (")
    Dim valuesToDelete As String() = TextBox1.Text.Split(vbNewLine)
    For i As Integer = 0 To valuesToDelete.Length - 1
        If i > 0 Then sb.Append(", ")
        
        Dim name As String = "@p" & i
        sb.Append(name)
        command.Parameters.AddWithValue(name, valuesToDelete(i))
    Next
    sb.Append(")");
    
    command.CommandText = sb.ToString()
    command.ExecuteNonQuery()
End Using

Alternatively, use Dapper[^]:
VB.NET
Dim valuesToDelete As String() = TextBox1.Text.Split(vbNewLine)
YourConnectionHere.Execute("DELETE FROM table_1 WHERE column1 IN (@ValuesToDelete)", New With { .ValuesToDelete = valuesToDelete })
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900