Beispiel #1
0
        public static void AddFacture(Facture facture)
        {
            SqlConnection sqlConnection = new SqlConnection(constr);

            sqlConnection.Open();
            String command = "INSERT INTO " + table + " VALUES(@Id , @num ,@date ,@fournisseur ," +
                             " @pretID" +
                             ",@produit,@Demand,@prix);";
            SqlCommand sqlCommand = new SqlCommand(command, sqlConnection);

            using (sqlCommand)
            {
                sqlCommand.CommandType = CommandType.Text;
                sqlCommand.Parameters.AddWithValue("@Id", facture.getid());
                sqlCommand.Parameters.AddWithValue("@num", facture.getNum());
                sqlCommand.Parameters.AddWithValue("@date", facture.getDate());
                sqlCommand.Parameters.AddWithValue("@fournisseur", facture.GetFournisseur().Id);
                if (facture.getprets_id() != 0)
                {
                    sqlCommand.Parameters.AddWithValue("@pretID", facture.getprets_id());
                }
                else
                {
                    sqlCommand.Parameters.AddWithValue("@pretID", DBNull.Value);
                }
                sqlCommand.Parameters.AddWithValue("@produit", facture.getproduit());
                if (facture.getdemand_id() != 0)
                {
                    sqlCommand.Parameters.AddWithValue("@Demand", facture.getdemand_id());
                }
                else
                {
                    sqlCommand.Parameters.AddWithValue("@Demand", DBNull.Value);
                }
                sqlCommand.Parameters.AddWithValue("@prix", facture.getprix());
                sqlCommand.ExecuteNonQuery();
            }
            sqlCommand.Dispose();
            sqlConnection.Close();
        }