<分区>
我正在尝试构建一些查询并使用 C# 将包含 7 列的列表插入到 SQL 表中。 在我的列表中,我有几个列的 NULL 值很少,我无法将它们传递给以下查询
string strInsertListToTable = @"INSERT INTO ImpliedOutrightData (id,product,term,bid,offer,bidcp,offercp) VALUES(@id,@product,@term,@bid,@offer,@bidcp,@offercp)";
for (int i = 0; i < resultList.Count; i++)
{
SqlCommand cmdInsertList = new SqlCommand(strInsertListToTable, sqlcon);
cmdInsertList.CommandType = CommandType.Text;
cmdInsertList.Parameters.Clear();
cmdInsertList.Parameters.AddWithValue("@id", resultList[i].id);
cmdInsertList.Parameters.AddWithValue("@product", resultList[i].product);
cmdInsertList.Parameters.AddWithValue("@term", resultList[i].term);
cmdInsertList.Parameters.AddWithValue("@bid", resultList[i].bid);
cmdInsertList.Parameters.AddWithValue("@offer", resultList[i].offer);
cmdInsertList.Parameters.AddWithValue("@bidcp",resultList[i].bidcp);
cmdInsertList.Parameters.AddWithValue("@offercp", resultList[i].offercp);
cmdInsertList.ExecuteNonQuery();
}
虽然上面的查询循环我得到了错误
The parameterized query '(@id int,@product nvarchar(2),@term nvarchar(5),@bid float,@bidc' expects the parameter '@offercp', which was not supplied.