I hope that my code will helpful with you.
Please modify it to your requirement.
#region Hàm thêm Product vào chi tiết order
public static void InsertCTOrder(int OrderID, int ProID, int Quantity, string UnitPrice,int ktra,SqlConnection sqlconn)
{
string strInSert = "INSERT INTO OderDetail VALUES (@OrderID, @ProID, @Quantity, @UnitPrice)";
SqlCommand sqlcmd = new SqlCommand(strInSert, sqlconn);
sqlcmd.Parameters.AddWithValue("@OrderID", OrderID);
sqlcmd.Parameters.AddWithValue("@ProID", ProID);
sqlcmd.Parameters.AddWithValue("@Quantity", Quantity);
sqlcmd.Parameters.AddWithValue("@UnitPrice", UnitPrice);
try
{
sqlconn.Open();
sqlcmd.ExecuteNonQuery();
sqlconn.Close();
ktra = 0;
}
catch (Exception )
{
sqlconn.Close();
ktra = 1;
}
}