从VB.NET文本框中删除oracle中的行 [英] Delete rows in oracle from VB.NET textbox

查看:92
本文介绍了从VB.NET文本框中删除oracle中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据vb.net文本框中的值删除oracle表中的所有行,TextBox包含column1中的值



我尝试过:



此代码仅删除oracle表格中文本框的第一行:



 For Each Name As String In TextBox1.Text.Split(vbNewLine)
str =从table_1删除其中column1 in('& name&')

解决方案

假设打开 OracleConnection 实例名为 YourConnectionHere

 使用命令作为 < span class =code-keyword>新 OracleCommand()
command.Connection = YourConnectionHere

Dim sb 作为 StringBuilder( DELET E FROM table_1 WHERE column1 IN(
Dim valuesToDelete As String ()= TextBox1.Text.Split(vbNewLine)
对于 i 作为 整数 = 0 valuesToDelete.Length - 1
如果 i> 0 然后 sb.Append( < span class =code-string>,)

Dim name 正如 字符串 = @ p& i
sb.Append(name)
command.Parameters.AddWithValue(name,valuesToDelete(i))
Next
sb.Append( );

command.CommandText = sb.ToString()
command.ExecuteNonQuery()
结束 使用



或者,使用 Dapper [ ^ ]:

  Dim  valuesToDelete  As   String ()= TextBox1.Text.Split(vbNewLine)
YourConnectionHere.Execute( DELETE FROM table_1 WHERE column1 IN(@ValuesToDelete) 使用 {.ValuesToDelete = valuesToDelete})


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 & "')"

解决方案

Assuming an open OracleConnection instance called YourConnectionHere:

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[^]:

Dim valuesToDelete As String() = TextBox1.Text.Split(vbNewLine)
YourConnectionHere.Execute("DELETE FROM table_1 WHERE column1 IN (@ValuesToDelete)", New With { .ValuesToDelete = valuesToDelete })


这篇关于从VB.NET文本框中删除oracle中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆