SQLCOMMAND.EXECUTENONQUERY
Olá galera, seguinte estou tentando criar um comando de exclusão de um registro no banco de dados, mas esta dando um erro e aparece a seguinte mensagem:
ArgumetNullException was unhandled
Valor não pode ser nulo. Nome do parâmetro: s
troublesshooting tips:
Use the [Ô]New[Ô] keyword to creat an object instance.
Check to determine if the object null before calling the method
Obs: Utilizo o visual basic
[ô]######################################################## Comando utilizado ####################################################
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
Dim sconnectionstring As String
Dim txtsql As String
[ô]Dim sCommand As String
[ô]Dim sqlCommand As SQLite.SQLiteCommand
sconnectionstring = [Ô]Data Source=C:\SCCV\Cadastros; Version=3;New=True;Compress=True;[Ô]
SQLconnect.ConnectionString = sconnectionstring
[ô]abre a conexão
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
[ô]Verfica se campo foi alterado
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]UPDATE CadastroPadrao SET TxtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[Ô] & TxtCodPadrao.Text
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtResolucao = [ô][Ô] & TxtResolucao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtTipoEquipamento = [ô][Ô] & TxtTipoEquipamento.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
End If
[ô] Fim da verificação
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
MsgBox([Ô]Registro ExcluÃdo com sucesso.[Ô])
Alguem pode ajudar-me?
Obrigado
ArgumetNullException was unhandled
Valor não pode ser nulo. Nome do parâmetro: s
troublesshooting tips:
Use the [Ô]New[Ô] keyword to creat an object instance.
Check to determine if the object null before calling the method
Obs: Utilizo o visual basic
[ô]######################################################## Comando utilizado ####################################################
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
Dim sconnectionstring As String
Dim txtsql As String
[ô]Dim sCommand As String
[ô]Dim sqlCommand As SQLite.SQLiteCommand
sconnectionstring = [Ô]Data Source=C:\SCCV\Cadastros; Version=3;New=True;Compress=True;[Ô]
SQLconnect.ConnectionString = sconnectionstring
[ô]abre a conexão
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
[ô]Verfica se campo foi alterado
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]UPDATE CadastroPadrao SET TxtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[Ô] & TxtCodPadrao.Text
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtResolucao = [ô][Ô] & TxtResolucao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtTipoEquipamento = [ô][Ô] & TxtTipoEquipamento.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
End If
[ô] Fim da verificação
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
MsgBox([Ô]Registro ExcluÃdo com sucesso.[Ô])
Alguem pode ajudar-me?
Obrigado
Qual a linha que dá o erro?
A linha que dá erro é:
SQLcommand.ExecuteNonQuery()
SQLcommand.ExecuteNonQuery()
Em algum lugar o parâmetro está sendo nulo, tente debugar para ver onde é.
Amigo, do jeito que está fazendo, vai executar o último delete, várias vezes...
Teria que ser:
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]UPDATE CadastroPadrao SET TxtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[Ô] & TxtCodPadrao.Text
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtResolucao = [ô][Ô] & TxtResolucao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtTipoEquipamento = [ô][Ô] & TxtTipoEquipamento.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
End If
Teria que ser:
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]UPDATE CadastroPadrao SET TxtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[Ô] & TxtCodPadrao.Text
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtResolucao = [ô][Ô] & TxtResolucao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtTipoEquipamento = [ô][Ô] & TxtTipoEquipamento.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
End If
[ô]#### Fiz isso ########
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
Dim sconnectionstring As String
Dim txtsql As String
sconnectionstring = [Ô]Data Source=C:\SCCV\Cadastros; Version=3;New=True;Compress=True;[Ô]
SQLconnect.ConnectionString = sconnectionstring
[ô]abre a conexão
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
[ô]Verfica se campo foi Excluido
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]Delete CadastroPadrao SET TxtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[Ô] & TxtCodPadrao.Text
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
End If
[ô] Fim da verificação
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
MsgBox([Ô]Registro ExcluÃdo com sucesso.[Ô])
[ô][ô] Dá o mesmo erro.
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
Dim sconnectionstring As String
Dim txtsql As String
sconnectionstring = [Ô]Data Source=C:\SCCV\Cadastros; Version=3;New=True;Compress=True;[Ô]
SQLconnect.ConnectionString = sconnectionstring
[ô]abre a conexão
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
[ô]Verfica se campo foi Excluido
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]Delete CadastroPadrao SET TxtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[Ô] & TxtCodPadrao.Text
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao SET TxtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
End If
[ô] Fim da verificação
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
MsgBox([Ô]Registro ExcluÃdo com sucesso.[Ô])
[ô][ô] Dá o mesmo erro.
Agora que eu notei... o comando SQL [Ô]Delete[Ô] não tem [Ô]SET[Ô], ou você apaga o registro ou atualiza os dados com o [Ô]UPDATE[Ô], esse sim, se usa o [Ô]SET[Ô]...
[ô]#### Fiz isso ########
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
Dim sconnectionstring As String
Dim txtsql As String
sconnectionstring = [Ô]Data Source=C:\SCCV\Cadastros; Version=3;New=True;Compress=True;[Ô]
SQLconnect.ConnectionString = sconnectionstring
[ô]abre a conexão
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
[ô]Verfica se campo foi Excluido
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]Delete CadastroPadrao txtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[Ô] & TxtCodPadrao.Text
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao txtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
End If
[ô] Fim da verificação
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
MsgBox([Ô]Registro ExcluÃdo com sucesso.[Ô])
[ô][ô] Dá o mesmo erro.
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
Dim sconnectionstring As String
Dim txtsql As String
sconnectionstring = [Ô]Data Source=C:\SCCV\Cadastros; Version=3;New=True;Compress=True;[Ô]
SQLconnect.ConnectionString = sconnectionstring
[ô]abre a conexão
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
[ô]Verfica se campo foi Excluido
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]Delete CadastroPadrao txtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[Ô] & TxtCodPadrao.Text
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete CadastroPadrao txtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
End If
[ô] Fim da verificação
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
MsgBox([Ô]Registro ExcluÃdo com sucesso.[Ô])
[ô][ô] Dá o mesmo erro.
txtsql = [Ô]Delete From CadastroPadrao Where txtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
Esse comando exclui todos os registros da tabela [Ô]CadastroPadrao[Ô], em que o campo [Ô]txtCodPadrao[Ô] contenha o valor que estiver na caixa de texto [Ô]TxtCodPadrao[Ô]
Verifique se:
1 - O nome do campo na tabela é mesmo esse(txtCodPadrao)
2 - Verifique se a caixa de texto [Ô]TxtCodPadrao[Ô] contém algum valor
Esse comando exclui todos os registros da tabela [Ô]CadastroPadrao[Ô], em que o campo [Ô]txtCodPadrao[Ô] contenha o valor que estiver na caixa de texto [Ô]TxtCodPadrao[Ô]
Verifique se:
1 - O nome do campo na tabela é mesmo esse(txtCodPadrao)
2 - Verifique se a caixa de texto [Ô]TxtCodPadrao[Ô] contém algum valor
[ô]#### Fiz isso ########
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
Dim sconnectionstring As String
Dim txtsql As String
sconnectionstring = [Ô]Data Source=C:\SCCV\Cadastros; Version=3;New=True;Compress=True;[Ô]
SQLconnect.ConnectionString = sconnectionstring
[ô]abre a conexão
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
[ô]Verfica se campo foi Excluido
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]Delete From CadastroPadrao Where txtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete From CadastroPadrao TxtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
End If
[ô] Fim da verificação
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
MsgBox([Ô]Registro ExcluÃdo com sucesso.[Ô])
[ô][ô] Estou incomodando pq realmente não sei o que acontece.
Dim SQLconnect As New SQLite.SQLiteConnection()
Dim SQLcommand As SQLiteCommand
Dim sconnectionstring As String
Dim txtsql As String
sconnectionstring = [Ô]Data Source=C:\SCCV\Cadastros; Version=3;New=True;Compress=True;[Ô]
SQLconnect.ConnectionString = sconnectionstring
[ô]abre a conexão
SQLconnect.Open()
SQLcommand = SQLconnect.CreateCommand
[ô]Verfica se campo foi Excluido
If TxtModeloPadrao.Enabled = True Then
txtsql = [Ô]Delete From CadastroPadrao Where txtCodPadrao = [ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
txtsql = [Ô]Delete From CadastroPadrao TxtModeloPadrao = [ô][Ô] & TxtModeloPadrao.Text & [Ô][ô][Ô] & [Ô] Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
SQLcommand.CommandText = txtsql
SQLcommand.ExecuteNonQuery()
End If
[ô] Fim da verificação
SQLcommand.ExecuteNonQuery()
SQLcommand.Dispose()
SQLconnect.Close()
MsgBox([Ô]Registro ExcluÃdo com sucesso.[Ô])
[ô][ô] Estou incomodando pq realmente não sei o que acontece.
A segunda Query também está errada. Deve ser mais ou menos assim:
txtsql = [Ô]Delete From CadastroPadrao Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
txtsql = [Ô]Delete From CadastroPadrao Where txtCodPadrao =[ô][Ô] & TxtCodPadrao.Text & [Ô][ô][Ô]
Tópico encerrado , respostas não são mais permitidas