How to delete information in BD using Datagridview?

Asked

Viewed 384 times

1

Can anyone tell me which command should I put to delete from the database using the information of the selected phone? I put it like this:

    SQLcmd.CommandText = ("DELETE FROM usuario WHERE nome = '" & DataGridView3.IsCurrentCellInEditMode & "' ")

inserir a descrição da imagem aqui

but apparently it didn’t work out....

1 answer

2


To take the value of datagrid would just be that:

var valordacelular = DataGridView3.CurrentCell.Value;

It is not indicated that you concatenate the direct value in string do not, below how your line would look, but that is not advisable.

SQLcmd.CommandText = ("DELETE FROM usuario WHERE nome = '" & DataGridView3.CurrentCell.Value & "' ");

The correct thing would be for you to add parameters within the String thus:

SQLcmd.CommandText = ("DELETE FROM usuario WHERE nome = @param1");
SQLcmd.CommandType = CommandType.Text;
SQLcmd.Parameters.Add(new SQLiteParameter("@param1", DataGridView3.CurrentCell.Value));
  • I understand, but your leave as you said my line would stay and it is not advisable, would have some execution problem?

  • There would be no execution problem.

  • i left it this way Sqlcmd.Commandtext = ("DELETE FROM user WHERE id = '" & Datagridview3.CurrentRow.Cells(0). Value & "' "

  • This, in case you take the selected line and the zero cell of it, will take the value of the id you want yes. Good that it helped you, if it answered your question does not fail to schedule answer.

  • thank you, help yes :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.