jak mogę zaktualizować logikę tabeli SQL
Mam tabelę zorganizowaną jako,
Table 3
Fruit ID - Foreign Key (Primary Key of Table 1)
Crate ID - Foreign Key (Primary Key of Table 2)
Teraz muszę wykonać zapytanie, które będzie,
Aktualizacja Crate ID
z Fruit ID
Jeśli Fruit ID
jest już w tabeli, a jeśli nie, wstaw rekord w tabeli 3 jako nowy rekord.
To właśnie mam teraz w kodzie,
private void RelateFuirtWithCrates(List<string> selectedFruitIDs, int selectedCrateID)
{
string insertStatement = "INSERT INTO Fruit_Crate(FruitID, CrateID) Values " +
"(@FruitID, @CrateID);"; ?? I don't think if it's right query
using (SqlConnection connection = new SqlConnection(ConnectionString()))
using (SqlCommand cmd = new SqlCommand(insertStatement, connection))
{
connection.Open();
cmd.Parameters.Add(new SqlParameter("@FruitID", ????? Not sure what goes in here));
cmd.Parameters.Add(new SqlParameter("@CrateID",selectedCrateID));
}