public static void InsertNewPurchses(int productId) { using (SqlConnection conn = new SqlConnection(Data.connectionString)) { conn.Open(); int p_count = CountPurchases(); string ac_code = ShopUtil.GenerateActCode(); string sql = @"insert into purchasedetails(PurchaseId, ProductId, ActivationCode) values (" + (p_count) + "," + productId + ",'" + ac_code + "')"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.ExecuteNonQuery(); } }