foreach (Example item in list) Json only get first Item?

You’re only executing the query once, outside the for loop. Structure your code as follows:

using (SqlConnection con = new SqlConnection(CS))
{
    con.Open();
    SqlCommand cmd = new SqlCommand("INSERT INTO Orders (orderId,consignmentNumber,itemNumbers,country,orderType,paymentTransactionId,priceInOre,paidAt,orderNumber,articleName) VALUES (@orderId,@consignmentNumber,@itemNumbers,@country,@orderType,@paymentTransactionId,@priceInOre,@paidAt,@orderNumber,@articleName)", con);                 
    
    foreach (Example item in list)
    {
        cmd.Parameters.Clear();
        // ... (set parameters)

        cmd.ExecuteNonQuery();
    }
    con.Close();
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top