I am trying to create a C# delete function. This is what I have so far, although I want to adapt it to work like my pseudo code below.
Pseudo code for new function
//public bool delete(Dictionary <string, string> id, string tableName)
//{
//reader or another object
//open conenction
//statement takes input of the primary key of the row to be edited
//as an array of one, the value plus the name of the column representing the primary key
//for the row to be deleted, as well as the table name
//connection
//excute
//return bool?
//}
//}
What I've tried:
public bool Delete(Dictionary <string, string> id, string tableName)
{
//reader or another object
//open connection
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("DELETE FROM tableName WHERE id=id", conn))
{
cmd.ExecuteNonQuery();
}
}
}
But when doing this I am struggling with adapting the code and would appreciate some help please. I can provide more info if needed. I want the new function to take the input of the unique identifier of the row to be edited as an array of one – the value plus the name of the column representing the primary key - for the row to be deleted, as well as the table name.