gpt4 book ai didi

c# - 在 C# 中向表中插入记录时无法将 NULL 值传递给参数

转载 作者:行者123 更新时间:2023-11-30 14:10:11 25 4
gpt4 key购买 nike

<分区>

我正在尝试构建一些查询并使用 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.

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com