123-c-sharp-sql-delete-command

Easier way to connect to database is

In this tutorial c sharp SQL delete command is explained, i.e. how to delete data with SQL query from C#. We continue from initial database tutorial.
C sharp SQL delete command for our example is following:

string str_name_surname = ltbxPersons.Items[ltbxPersons.SelectedIndex].ToString();

DialogResult dlDialog = MessageBox.Show(“Do you want to delete ” + str_name_surname + “?”, “Question”, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

if (dlDialog == DialogResult.Yes)
{

string str_selected_id = alConnection[ltbxPersons.SelectedIndex].ToString();

string str_sql_delete = “delete from [PERSON] where ID_PERSON = ” + str_selected_id;

sqlCn.Open();
sqlCmd.CommandText = str_sql_delete;
sqlCmd.ExecuteNonQuery();
sqlCn.Close();

list_of_persons();
clear_all_fields();
}

External links:

C Sharp SQL Delete Command on Developerfusion
C Sharp SQL Delete Command on Daniweb

Posted in c-sharp-code-examples

Leave a Reply

Your email address will not be published. Required fields are marked *

*