【发布时间】:2013-05-08 12:08:34
【问题描述】:
我有一个结构如下的表格,
Table 3
Fruit ID - Foreign Key (Primary Key of Table 1)
Crate ID - Foreign Key (Primary Key of Table 2)
现在我需要执行一个查询,
更新 Crate ID of Fruit ID if Fruit ID 已经在表中,如果没有则插入记录在表 3 中作为新记录。
这是我现在在代码中得到的,
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));
}
【问题讨论】:
标签: c# sql sql-server webforms