XerTroV Posted May 28, 2022 at 09:01 AM Report Share #626075 Posted May 28, 2022 at 09:01 AM (edited) Bom dia estou tendo problema para excluir dados no sql com múltiplas condições no vb net por meio de combobox comando : Using cn = New SqlConnection(StrCon) cn.Open() Dim sql As String = "Delete from dbo.Clientes where AccountID='" & ComboBox1.Text & "'" And " Tipo='" & ComboBox2.Text & "'" Using cmd = New SqlCommand(sql, cn) cmd.ExecuteNonQuery() End Using End Using Esta me retornando o erro System.InvalidCastException: 'Conversion from string "Delete from Clientes whe" to type 'Long' is not valid.' Poderia me ajudar ? Obrigado . Edited May 29, 2022 at 03:19 PM by XerTroV Link to comment Share on other sites More sharing options...
iznougudpt Posted May 29, 2022 at 01:32 PM Report Share #626078 Posted May 29, 2022 at 01:32 PM O que tem em ComboBox1.Text e ComboBox2.Text? Qual é a query final? Link to comment Share on other sites More sharing options...
XerTroV Posted May 29, 2022 at 03:35 PM Author Report Share #626079 Posted May 29, 2022 at 03:35 PM 1 hora atrás, iznougudpt disse: O que tem em ComboBox1.Text e ComboBox2.Text? Qual é a query final? Olá a instrução do button : Public Sub Delete() Using cn = New SqlConnection(StrCon) cn.Open() Dim sql As String = "Delete from dbo.Cliente where AccountID='" & ComboBox1.Text & "'" And " Tipo='" & ComboBox2.Text & "'" Using cmd = New SqlCommand(sql, cn) cmd.ExecuteNonQuery() End Using End Using End Sub No combobox1 tem os clientes que são carregados do sql, no combobox2 tem o tipo de clientes são numerados de 0 a 9 a tabela seria mais o menos assim : Cliente Tipo Banco Ana 1 250 Ana 2 300 Celso 1 233 A minha intenção seria ao selecionar o usuario Ana no combobox1 e o tipo 2 no combobox2 ele apagasse a linha: Ana 2 300 Pois tentei desta forma : Public Sub Delete() Using cn = New SqlConnection(StrCon) cn.Open() Dim sql As String = "Delete from CustomLuckyWheel where AccountID='" & ComboBox1.Text & "'" Using cmd = New SqlCommand(sql, cn) cmd.ExecuteNonQuery() End Using End Using End Sub Só que assim ele apaga todos os registros no usuário selecionado na combobox1 Obrigado Link to comment Share on other sites More sharing options...
Solution iznougudpt Posted May 30, 2022 at 11:33 AM Solution Report Share #626083 Posted May 30, 2022 at 11:33 AM Dim sql As String = "Delete from dbo.Clientes where AccountID='" & ComboBox1.Text & "' And Tipo='" & ComboBox2.Text & "'" O AND tem de estar na query, tinhas aspas a mais. 1 Report Link to comment Share on other sites More sharing options...
XerTroV Posted May 30, 2022 at 08:45 PM Author Report Share #626086 Posted May 30, 2022 at 08:45 PM Obrigado man, Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now