I am trying to build some query and insert a list with 7 columns into a SQL table using C#. In my list I have few NULL values for few columns and I am not able to pass them to the following query
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();
}
While the above query loops I get the error
The parameterized query '(@id int,@product nvarchar(2),@term nvarchar(5),@bid float,@bidc' expects the parameter '@offercp', which was not supplied.