How to erase information in DB using DataGridView?

1

Can anyone tell me what command I should put to delete the database using the selected cell information? I put it like this:

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

But apparently it did not work ....

    
asked by anonymous 06.12.2015 / 19:41

1 answer

2

To get the value of the dataGrid would be just that:

var valordacelular = DataGridView3.CurrentCell.Value;

You are not required to concatenate the direct value in the string of SQL, not below how your row would stay, but that is not advisable.

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

The correct one would be to add parameters within the String like this:

SQLcmd.CommandText = ("DELETE FROM usuario WHERE nome = @param1");
SQLcmd.CommandType = CommandType.Text;
SQLcmd.Parameters.Add(new SQLiteParameter("@param1", DataGridView3.CurrentCell.Value));
    
06.12.2015 / 21:54